Serverban not working

This is the handler

local sBan = {

}

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

game.Players.PlayerAdded:Connect(function(plr)
	if table.find(sBan, plr.Name) then
		plr:Kick("Je bent verbannen van deze server, let op. Dit is een serverban geen gameban.")
	end
end)

And this is the fire script

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.SBan:FireServer(script.Parent.Parent.Parent.BanFrame.Persoon.Text, script.Parent.Parent.Parent.BanFrame.Reden.Text)
end) 

The script gives no errors.

This works on a Admin Panel.

Actually I HAD IT all mixed up, you’re trying to ban THE player who fired the event NOT the actual player who gets banned.

game.ReplicatedStorage.SBan.OnServerEvent:Connect(function(innocentplayer, BannedPlayer, Reason)
	table.insert(sBan, game:GetService("Players"):FindFirstChild(BannedPlayer).UserId)
        --optional kick
        --game:GetService("Players"):FindFirstChild(BannedPlayer):Kick(Reason)
end)
game.Players.PlayerAdded:Connect(function(plr)
	if table.find(sBan, plr.UserId) then
		plr:Kick("Je bent verbannen van deze server, let op. Dit is een serverban geen gameban.")
	end
end)
1 Like

Ah I see it now, When you’re firing client to server, the first word on the parameter is always to be player right?OnServerEvent:Connect(function(PlayerWhoFiredServer)

That is correct.

Hmm, the ban button is not working.

How do you know the ban button does not work

I don’t know,

This is the console with checks.
image

Check 4/5 doesn’t work now.

game.Players.PlayerAdded:Connect(function(plr)
	print("check 3")
	if table.find(sBan, plr.Name) then
		print("check 4")
		plr:Kick("Banned")
		print("check 5")
	end
	print("check6")

What do these check, show me the button script

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.SBan:FireServer(script.Parent.Parent.Parent.BanFrame.Persoon.Text, script.Parent.Parent.Parent.BanFrame.Reden.Text)
end)

Show me the whole script of all things that has to do with server ban

You typed the user name correctly?

Is my snippet working?

Yes username is correct.

Could it be because he puts you in the table when you click on the ban button but don’t kick yet.

You should use userid instead, try my script and see if it works.

Where is your script? I see no script here.

Yes because you put him in the table but never added the kick within the on button click

game.ReplicatedStorage.SBan.OnServerEvent:Connect(function(innocentplayer, BannedPlayer, Reason)
	table.insert(sBan, game:GetService("Players"):FindFirstChild(BannedPlayer).UserId)
        --optional kick
        --game:GetService("Players"):FindFirstChild(BannedPlayer):Kick(Reason)
end)
game.Players.PlayerAdded:Connect(function(plr)
	if table.find(sBan, plr.UserId) then
		plr:Kick("Je bent verbannen van deze server, let op. Dit is een serverban geen gameban.")
	end
end)

This solution should work if you encounter any issues please tell me.
In the script there are comments telling you where to add the following scripts.
Remember to change the button argument!

-- Code below in a Script inside ServerScriptService

local ServerBanned = { }
local Insert = table.insert
local Find = table.find

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
    if Find(ServerBanned, Player.Name) then
        Player:Kick("Hey you have been banned from this server!")
    end
end)

local SBan = game:GetService("ReplicatedStorage"):WaitForChild("SBan")

SBan.OnServerEvent:Connect(function(Player, PlayerToBan, Reason)
    -- this remote is unsecured if the server ban is reserved only to you then add a check if the user id is yours or make a table containing whitelisted userids and check if the userid is one of the values inside the table.
    
    local PlayerToBan = PlayerToBan and Players:FindFirstChild(PlayerToBan)
    
    if not PlayerToBan then
        return
    end
    
    Insert(ServerBanned, PlayerToBan)
    PlayerToBan:Kick(Reason or "Server Banned please join another server.")
end)

-- Instead this code belongs in a localscript parented to a Button.

local Parent = script.Parent
local SBan = game:GetService("ReplicatedStorage"):WaitForChild("SBan")

Parent.Activated:Connect(function()
    SBan:FireServer("text instance here (obviously not as a string", "if you wanna dd a reason then add it here")
end)

Yes it works now I hadn’t placed a kick up there.

Only now the question how do I fix that the reason is saved and I can specify it later.