I am making chat commands for my game that only staff can use but I cannot get the staff check to work
local Staff = require(game:GetService("ServerScriptService"):WaitForChild("StaffList"))
local StaffCmds = {
"/kick";
"/ban";
"/unban";
"/tp";
"/tphere";
}
local function checkPlayer(UserId)
for _, StaffId in pairs(Staff) do
if UserId == StaffId then
return true
end
end
return false
end
local function findPlayer(name)
local NameLength = string.len(name)
for _, player in pairs(game.Players:GetPlayers()) do
if string.sub(player.Name,1,NameLength):lower() == name then
return player
end
end
return nil
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg, sender)
msg = string.lower(msg)
local splitString = msg:split(" ")
local cmdName = splitString[1]
if table.find(StaffCmds, cmdName) then
local isStaff = checkPlayer(sender.UserId)
if isStaff == true then
if cmdName == "/kick" then
local PlrToKickName = splitString[2]
local Reason = splitString[3]
if PlrToKickName then
local PlrToKick = findPlayer(PlrToKickName)
if PlrToKick then
print(PlrToKick)
PlrToKick:Kick(Reason)
end
end
end
end
end
end)
end)