|
I'm making an admin GUI. But there's one thing I need help with:
How do I make a modulescript where it reads who's an admin and who's not an admin? |
|
GGGGG14Join Date: 2012-01-29 Post Count: 27026 |
local AdminModule = {}
AdminModule.Administrators = {"Name", "Name2", "Name3", "etc"}
AdminModule.IsAdmin = function(Table, User)
for Index = 1, #Table do
if Table[Index] == User.Name then
return true
end
end
end
return AdminModule; |
|
|
|
@Azure
Disgusting...
local adminModule = {};
adminModule.administrators = { Name = true; Name2 = true; Name3 = true; etc = true; };
adminModule.isAdmin = function(table, user, bool)
if (bool) then
if (table[user.Name]) then
return true;
end; else
for i = 1, #table do
if (table[i] == user.Name) then
return true;
end; end; end; end;
return adminModule; |
|
|
One thing:
Can the module give the admin gui to the specific user? Let's say the script makes the gui visible since the gui is in the script. How do I make it where It copys the gui to the user who's been picked?
Just a quick question. |
|
GGGGG14Join Date: 2012-01-29 Post Count: 27026 |
@Palm you literally have no idea what you're talking about.
A numerical for loop runs three times as fast as your two conditionals + numerical for loops and you're just following what the wiki said, but my function returns if the name is in the table, rather than a useless bool that goes along with it. |
|
|
@Azure
Please tell me where I am following the wiki? I'm rather... confused... on that part.
I was just going to use indexes flat-out, but most people use the hideous for loop, so I decided to add a bit of support for that. If I didn't, it'd be something like this (which is, to my knowledge, more efficient):
local adminModule = {};
adminModule.administrators = { Name = true; Name2 = true; Name3 = true; etc = true; };
adminModule.isAdmin = function(table, user)
if (table[user.Name]) then
return true;
end; end;
return adminModule; |
|
GGGGG14Join Date: 2012-01-29 Post Count: 27026 |
@Thread maker -- (This is in a normal script)
local requiredMod = require(Workspace.AdminModule);
local Gui = blahblah
game:GetService("Players").PlayerAdded:connect(function(newUser)
if requireMod.IsAdmin(requiredMod.Administrators, newUser) then
Gui:Clone().Parent = newUser:WaitForChild("PlayerGui")
end
end) |
|
GGGGG14Join Date: 2012-01-29 Post Count: 27026 |
@Palm, yes your second script would be more efficient, but your first had multiple conditionals which are less efficient. |
|
GGGGG14Join Date: 2012-01-29 Post Count: 27026 |
@Thread maker, I made a typo, it should be 'requiredMod' |
|
|
@Azure
I have seen many people make less efficient, yet more compatible, scripts. That is simply what I did. |
|
|
|
I found a problem:
In the server console, the admin script says that "IsAdmin" is a nil value. |
|
|