Simple administration system help

Hi,

I have managed to create a simple system that allows the player to type “/lockbox” to lock an area. I now want to add onto this, and make it so the script will detect the sender and make sure the sender is in a list.

This is my current code.

local admins = {"pevdn"}

local prefix = "/"
local lockbox = "lockbox"
local unlockbox = "unlockbox"

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg:lower() == (prefix..lockbox) then
			game.Workspace.Part.Transparency = 0
		end
	end)
end)

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg:lower() == (prefix..unlockbox) then
			game.Workspace.Part.Transparency = 1
		end
	end)
end)

How can I make it detect if the player is in the “admins” list?

it is simple, just use table.find()

if not table.find(plr.Name, admins) then return end

not table.find() means he isn’t in the table so we “return” which stops the function from working

1 Like

You can add the admin userids (I recommend userids above usernames because usernames can change, userids won’t.) to a table and then between the playeradded and the plrchatted function add an if statement with table.find and then run the function, so if the userid is in the table with admin ids then the rest will run, else you return end.

Sorry if this sounds like a stupid question, but where would I put this in the code?

You add it under game.Players.PlayerAdded:Connect(function(plr)

[quote=“pevdn, post:1, topic:1877182”]

local admins = {"152135123"}

local prefix = "/"
local lockbox = "lockbox"
local unlockbox = "unlockbox"

game.Players.PlayerAdded:Connect(function(plr)
       if not table.find(admins, plr.UserId) then return end
	plr.Chatted:Connect(function(msg)
		if msg:lower() == (prefix..lockbox) then
			game.Workspace.Part.Transparency = 0
		end
	end)
end)

game.Players.PlayerAdded:Connect(function(plr)
       if not table.find(admins, plr.UserId) then return end
	plr.Chatted:Connect(function(msg)
		if msg:lower() == (prefix..unlockbox) then
			game.Workspace.Part.Transparency = 1
		end
	end)
end)

After the player Added function or the Chatted function

Now I get an error,

" 18:08:58.152 Workspace.AE - ADMINISTRATION ESSENTIALS.Main.V0.0.0:8: invalid argument #1 to ‘find’ (table expected, got string) - Server - V0.0.0:8"

Updated code:

local admins = {"pevdn"}

local prefix = "/"
local lockbox = "lockbox"
local unlockbox = "unlockbox"

game.Players.PlayerAdded:Connect(function(plr)
	if not table.find(plr.Name, admins) then return end
	plr.Chatted:Connect(function(msg)
		if msg:lower() == (prefix..lockbox) then
			game.Workspace.Part.Transparency = 0
		end
	end)
end)

game.Players.PlayerAdded:Connect(function(plr)
	if not table.find(plr.Name, admins) then return end
	plr.Chatted:Connect(function(msg)
		if msg:lower() == (prefix..unlockbox) then
			game.Workspace.Part.Transparency = 1
		end
	end)
end)

My bad change it to table.find(admins, plr.name) I apologize.

You don’t have to do the whole function again for every command, you can just do the playeradded and the plr.chatted once.