I was creating a ban/warning system where basically I type ;warnPlayer [player]. Then it gives me a UI where I send a personalized message to the player and a warning to follow the rules. The only issue is that it only works on one player per server.
If you don’t understand what I mean, look here:
- I use ;warnPlayer on Player1 to tell them to follow the rules. Everything works successfully.
- I use ;warnPlayer on another player, Player2 to be specific, because they were exploiting. However, it gives the warning to Player1 and Player2 gets no warning.
I scripted the commands based on Alvin Blox’s admin command video, and I added my own touch to give the GUIs and such.
Here is my script in ServerScriptService:
local commands = {}
local prefix = ";"
local function findPlayer(name) -- finds player object based on the username typed
for i, player in pairs(game.Players:GetPlayers()) do
if string.lower(player.Name) == name then
return player
else
return nil
end
end
end
commands.warnplayer = function(sender, arguments) --the function
if sender.Name == "ActiveFrenzy" then -- I am the only person who can do this
for i, object in pairs(arguments) do
print(object)
end
local recipientName = arguments[1]
game.ReplicatedStorage.InputWarning:FireClient(sender) -- enables a GUI on my side so that I can send a personalized message that the entire server won't see
if recipientName then
local playerToSendWarningTo = findPlayer(recipientName)
if playerToSendWarningTo then
game.ReplicatedStorage.GiveWarningToServer.OnServerEvent:Connect(function(confirmer, message) -- this is fired when I give my input
if confirmer == sender then -- makes sure an exploiter doesn't try to give random warnings to people
if message == "Cancel" then return end -- this happens if I click the X button to cancel the GUI and the warning
game.ReplicatedStorage.GiveWarning:FireClient(playerToSendWarningTo, message) -- gives warning to player
return
end
end)
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message, recipient) -- checks if player chatted
message = string.lower(message)
local splitString = message:split(" ")
local slashCommand = splitString[1]
local cmd = slashCommand:split(prefix)
local cmdName = cmd[2]
if commands[cmdName] then
local arguments = {}
for i = 2, #splitString, 1 do
table.insert(arguments, splitString[i])
end
commands[cmdName](player, arguments) -- in this case, it fires warnPlayer()
end
end)
end)
I’m honestly really confused as to why this happens and would appreciate if anyone could help me figure this out, as I don’t want to warn the wrong players. Thank you in advance!