How would I go about for a table admin script?

Hey Developers!

I was making a command that if you say !training it moves my training equipment from ServerStorage to Workspace.

However, I want it that only I can do it, or maybe other players in a table.

But, I suck with tables, and I need help.

local prefix = "!"
local admins = "AmariGXL"

-- if chat message by admins is !training then move model from serverstorage to workspace
game:GetService("Players").PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(message)
        if message == prefix.."training" and admins then
            local model = game.ServerStorage["Training Gear"] -- change ModelName to the name of your model in ServerStorage
            model.Parent = workspace
        end
    end)
end)

The script works just fine, but it has it that anybody can do it, now i just but “admins” but that obviously doesn’t work.

Any help?

What you’re trying to do is pretty simple; here is how you’d go about doing it.

  1. Create a table with string values, being usernames (or userids being number values, if you’re worried about people changing their usernames)

  2. Use table.find to check if the players username or userid is inside the table whenever they try to use a command

1 Like

Basically what @txcIove said:

local prefix = "!"
local admins = {"AmariGXL", "Roblox"} -- Converted to a table, "Roblox" can be replaced with a different username

-- if chat message by admins is !training then move model from serverstorage to workspace
game:GetService("Players").PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(message)
        if message == prefix.."training" and table.find(admins, player.Name) then
            local model = game.ServerStorage["Training Gear"] -- change ModelName to the name of your model in ServerStorage
            model.Parent = workspace
        end
    end)
end)

Realistically you should be using UserIDs for security reasons, for example if you changed your username and someone took the old username, they could gain free admin if you forget to change it here.

2 Likes

I didn’t even know you can take old names, thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.