So I am trying to make a ban script. WHen a player bans somebody it inserts them into a table and if they rejoin then it kicks them from the server. I have it to ban one player but when I try to ban another player in the server they can rejoin. How can I make the script so if the person is in the array, they cannot rejoin?
`` local Webhook = "WEBHOOK HERE NOT PUTTING IT"
local Banned = {}
game.ReplicatedStorage.BanEvent.OnServerEvent:Connect(function(PlayerName,Player,Reason,Person) local thing = { content = Person.." Banned ".. Player .. " for ".. Reason } local DataCome = HTTP:JSONEncode(thing) HTTP:PostAsync(Webhook, DataCome)
local players = game:GetService("Players")
table.insert(Banned, Player)
game.Players:FindFirstChild(Player):Kick("You have been banned for ".. Reason)
while true do wait()
game.Players.PlayerAdded:Connect(function(plr)
if plr.Name == Banned[1] then
plr:Kick('Backlisted from this server')
end
end)
end
end) ``

3 comments
If you want to make a Server-specific blacklist, a Dictionary cache is the best approach. Map each user's UserId to a truthy attribute and then simply index them–for a O(1) lookup complexy–under their UserId upon reconnection.
Note: You're perpetually spawning RBXScriptConnections to the same RBXScriptSignal with an identical Callback, this is unnecessary and is** causing a memory leak.
Keep the 'PlayerAdded' signal outside of the 'OnServerEvent' Callback and rid of your redundant loop. Then you can simply search for an entry under the UID you assigned.