Problem with Admin Panel - Unban

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)
  • No Errors.

Alright, so what is the problem with your script? Is it seemingly not running? Is only unban not working? Can any player user it?

Only unban is not working, Not everyone can use it is on rank.

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:

table.remove(sBan, table.find(sBan, game.Players[plrToUnban.UserId))

Ohh thanks, iam going to test it.

And also wouldn’t the banned player not even exist within the game?

Why that errors.

@bluebxrrybot can you help with this?

These errors.

Send the error message please. To do so, hover over the text and you’ll likely be prompted a syntax error.

image

That’s a synopsis of something else. If you hover over the text with the red underline, it should give you a message.

ServerScriptService.BanHandler:26: Expected ‘)’ (to close ‘(’ at line 25), got ‘else’

Oh you need to close the table.remove functions with a “ ) “

Done alone it doesn’t keep working. Your word has not been banned.

image

ERROR

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

You forgor a ) after the table.remove.

How do I add this to the script?

Here’s the script.

game.ReplicatedStorage.Unban.OnServerEvent:Connect(function(Player, plrToUnban)
game.Players:WaitForChild(plrToUnban)
table.remove(sBan, table.find(sBan, game.Players[plrToUnban.UserId]))
end)

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)

Thanks for helping, it works now.