local isAdmin = {[""] = true, [""] = true, [""] = true} function onChatted(message, player) if message == "pprainplz" and isAdmin[player.Name] then game.Workspace.PPRain.Disabled = false game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(message) onChatted(message, player) end) end)
Ive tried to do this but it wont work when i say pprainplz to make it rain the parts from the other script, and i know the other works because i've tried it
The PlayerAdded
event in this code will never run because it is inside the onChatted
function which is never called. You are also missing multiple end's
in your code.
local isAdmin = {[""] = true, [""] = true, [""] = true} function onChatted(message, player) if message == "pprainplz" and isAdmin[player.Name] then game.Workspace.PPRain.Disabled = false end end game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(message) onChatted(message, player) end) end)
To further improve this code you can use a function to check if the player is in the table. So you do not have to set each player to true. This function is also not case sensitive.
I also only call the onChatted
function if the player is considered an admin. This allows for less code repetition if you wish to make multiple admin commands.
local isAdmin = {"Bob", "Joe"} function inAdminTable(Name) for _,n in pairs(isAdmin) do if n:lower() == Name:lower() then return true end end end function onChatted(message, player) if message == "pprainplz" then game.Workspace.PPRain.Disabled = false end end game.Players.PlayerAdded:connect(function(player) if inAdminTable(player.Name) then player.Chatted:connect(function(message) onChatted(message:lower(), player) end) end end)