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) ``
The main problem with your ban script is it won't really fire because your functions are right within "BanEvent."
local players = game:GetService("Players") local Banned = {} -- I made a mistake earlier game.ReplicatedStorage.BanEvent.OnServerEvent:Connect(function(PlayerName, Reason, PersonWhoGotBanned) -- "PlayerName" holds the name of the banned player simply by "PlayerName.Name" -- Im going to assume this is correct and working. local thing = { content = PlayerName.Name.." Banned ".. PersonWhoGotBanned .. " for ".. Reason } local DataCome = HTTP:JSONEncode(thing) HTTP:PostAsync(Webhook, DataCome) table.insert(Banned, PersonWhoGotBanned) if players[PersonWhoGotBanned] then players[PersonWhoGotBanned]:Kick("You have been banned for ".. Reason) else warn('Could not find', PersonWhoGotBanned) end end) -- End of BanEvent. Hopefully your remote event should still work. Otherwise ask again. -- Leave this out of the "BanEvent." It will fire automatically once they rejoin. players.PlayerAdded:Connect(function(player) for _, bannedPlayer in pairs(Banned) do -- Loop through the entire array if player.Name == bannedPlayer then -- Compare the items from that array with the player name player:Kick("You're banned from this server") else continue end end end)