Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Would this work for a basis of an admin commands script?

Alright, my previous question about admin commands was very helpful with the answers, however I am now in need of help again, I can't test them at the moment, so I need to know if I have created a good "Basis" for the admin commands as the entire script is within an anonymous function, and then then a function within it is the actual commands and levels, I need help with this part as I dont know if it would work.

local adminlist = {
[game.CreatorId] = {3},
[NormalAdminId] = {2},
[Moderator] = {1},
}
-- the level of the admin goes 3(Owner kind of commands, if the admin has this they have access to all commands), 2(General commands such as kick, ff, etc...), 1(commands like ff, tp, and msg, nothing abusive)
game.Players.PlayerAdded:connect(function(plr)
function levels()
for _,v in pairs(adminlist) do
if v == "3" then
-- add commands for level 3 users

elseif  v == "2" then
-- add commands for level 2 users

elseif  v == "1" then
-- add commands for level 1 users

elseif  plr ~= v then
print("IsNotAdmin")
end
end
end
end
end
end
end

levels()
end)

Any and all help works.

1 answer

✓ Accepted answer

1st pls can you format your code correctly by using tabs it makes it a lot easier to read where each end goes.

Currently your code will not work as you want it because this is a index value table

for _,v in pairs(adminlist) do -- if you wanted to do a index, value loop the format is for  [variable for index usualy i], [variable for value usualy v]
	if v == "3" then -- this will always run as you do not check the player userid so the first value in the table will allways be 3
	-- add commands for level 3 users
	
	elseif  v == "2" then
	-- add commands for level 2 users
	
	elseif  v == "1" then
	-- add commands for level 1 users
	elseif  plr ~= v then
		print("IsNotAdmin")
	end
end

You do no need to use the loops so lets fix this.

local adminlist = {
	-- so just to make 100% shure the [needs the user id] so we dont need loops
	[game.CreatorId] = {3},
	[NormalAdminId] = {2},
	[Moderator] = {1},
}

game.Players.PlayerAdded:connect(function(plr)
	
	local function levels(plr)
		if adminlist[plr.UserId] == 3 then
			-- level 3 cmds
		elseif adminlist[plr.UserId] == 2 then
			-- level 2 cmds
		elseif adminlist[plr.UserId] == 1 then
			-- level 1 cmds
		else
			-- this should never happern but o well
		end
	end
	
	if adminlist[plr.UserId] ~= nil then -- check that the user is in our list before adding things, nil is returned if not in list so this will not run
		levels(plr)
	end
end)

3 comments

0

You're a smart fellow.

0

;) I need a fun question to do

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.