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)
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)
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)
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")
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)