Server Ban system

So What im trying to achieve is a Server Ban System Using Tables
A Solution i have tried is Searching Tables on Developer Hub

the Code i Have is

local sBan = {
	
}

game.ReplicatedStorage.SBan.OnServerEvent:Connect(function(plrToBan, Reason)
	table.insert(plrToBan)
	game.Players.PlayerAdded:Connect(function(plr)
		if plr.Name == table[1] then
			plr:Kick("You Have been Banned in this Server for: "..Reason.."/n You Do Not Have to Appeal as this is not a game ban")
		end
	end)
	
end)

You should use DataSoreService and save the banned players table.
Edit: sorry I didnt saw this is a server ban.

Couple problems

  • That’s not how you insert something into a table. You do it like this:
    table.insert(sBan, plrToBan)
  • You’re just comparing the name of the player against the first entry of the table. To look through the table for a name, do this:
    if table.find(sBan, plr.Name) then
  • Define the playerAdded Connection outside the onServerEventConnection
  • This would ban the player who fired the event, since the first parameter of onServerEvent is the client that fired the remote event.
3 Likes
local BannedPlayers = {'Player', 'Player2', 'Player3'}

game.Players.PlayerAdded:Connect(function(Player)
    for i, BannedPlayer in pairs(BannedPlayers) do
    	if BannedPlayer == Player.Name then
    		Player:kick('You are banned from this game.')
    	end
    end
end)
1 Like

Would the Script be

local sBan = {
	
}

game.ReplicatedStorage.SBan.OnServerEvent:Connect(function(plrToBan )
	table.insert(sBan, plrToBan)
	
	
end)





game.Players.PlayerAdded:Connect(function(plr)
	if table.find(sBan, plr.Name) then
		plr:Kick("You Have Been Banned From this Server")
	end
	
end)

You’ll need to kick them when they’re added to the table, also your server banning yourself when your firing the remote.