local sBan = {
}
game.ReplicatedStorage.SBan.OnServerEvent:Connect(function(Player, plrToBan, Reason)
--if plrToBan:FindFirstChild("Admin").Value == true then Player.PlayerGui["Admin Panel"].MainFrame["Server Ban"].BanFrame.BanButton.Text = "Je kan geen staff leden bannen."
--wait(2)
--Player.PlayerGui["Admin Panel"].MainFrame["Server Ban"].BanFrame.BanButton.Text = "Ban"
--else
if not game.Players:FindFirstChild(plrToBan) then
game.Players:WaitForChild(plrToBan)
table.insert(sBan, game:GetService("Players"):FindFirstChild(plrToBan).UserId)
game:GetService("Players"):FindFirstChild(plrToBan):Kick("SERVERBAN | ".. Reason)
else
table.insert(sBan, game:GetService("Players"):FindFirstChild(plrToBan).UserId)
game:GetService("Players"):FindFirstChild(plrToBan):Kick("SERVERBAN | ".. Reason)
--end
end
end)
game.ReplicatedStorage.Unban.OnServerEvent:Connect(function(Player, plrToUnban)
if not game.Players:FindFirstChild(plrToUnban) then
game.Players:WaitForChild(plrToUnban)
table.remove(sBan, game:GetService("Players"):FindFirstChild(plrToUnban).UserId)
else
table.remove(sBan, game:GetService("Players"):FindFirstChild(plrToUnban).UserId)
game:GetService("Players"):FindFirstChild(plrToUnban)
end
end)
game.Players.PlayerAdded:Connect(function(plr)
if table.find(sBan, plr.UserId) then
plr:Kick("SERVERBAN | You have been banned from this server, which means that you have no access to participate in this server. [!] NB! [!] This is only in this server, you can join the next server again.")
end
end)
Oh, the issue is that you’re using table.remove wrong. It takes two arguments: table, tableindex. You’re using it like this: table, item. Use table.find to get the index:
@PollStand_Dev is correct, in the ban you can use the Players Service because before the ban the player is obviously still in the game, however in the unban won’t work because it will never find the player to unban because he directly gets kicked when he joins so there’s no way for him to be in the game at the point you want to unban him. Like blueberry said you can only use table.remove with an index but you don’t want to search with game.Players, instead the index is table.find(sBan, userID) because you added the players userID to the sBan table. You can get the userID with PlayerService:GetUserIdFromNameAsync(username)
Remove WaitForChild(plrToUnban) because game.Players is a list of players in the current server and the banned player isn’t in the server
-- You should protect this remote event because otherways exploiters can fire it
-- for example use player:GetRankInGroup(YOUR_GROUP_ID) > SPECIFIC_ROLE_ID
game.ReplicatedStorage.Unban.OnServerEvent:Connect(function(Player, plrToUnban)
local userID = game.Players:GetUserIdFromNameAsync(plrToUnban)
local index = table.find(sBan, userID)
table.remove(sBan, index) -- if you declare a variable for it the code is cleaner
end)