Unban not working of custom admin GUI

My custom admin GUI’s unban function does not work.
The ban/unban system works on tables
I have tried numerous methods, All have failed.
Current script:

Script
remoteEvent2.OnServerEvent:Connect(function(player, Username, Reason, Type)
	local UserId = game.Players:GetUserIdFromNameAsync(Username)
	if table.find(Allowed, player.UserId) then
		if game.Players:FindFirstChild(Username)  and Type == "Kick" then
			game.Players:FindFirstChild(Username):Kick(Reason)
		elseif game.Players:FindFirstChild(Username) and Type=="Ban" then
			table.insert(Banned, game.Players:FindFirstChild(Username).UserId)
			game.Players:FindFirstChild(Username):Kick("You have been banned from this server. Reason: "..Reason)
		elseif game.Players:FindFirstChild(Username) and Type=="Unban" then
			local success, failure = pcall(function()
				table.remove(Banned, UserId)
			end)
			if success then
				remoteEvent4:FireClient(player, "Unban System","Unban successful!", 7.5)
			else
				remoteEvent4:FireClient(player, "Unban System","Unban failed! User was not found.", 7.5)
			end
		end
	elseif not table.find(Allowed, player.UserId) then
		table.insert(Banned, player.UserId)
		if Type=="Kick" then
			player:Kick("nice try "..Type.."ing someone ya big exploiter")
			Reason="Exploiting"
		else
			player:Kick("nice try "..Type.."ning someone ya big exploiter")
			Reason="Exploiting"
		end
	end
	serverbanreason=Reason
end)

Help highly appreciated.

1 Like

The table.remove function uses a index, instead of finding the said item in the table.
A solution to this can be using table.find.

table.remove(table.find(Banned, UserId))

I hope this helps.

doesnt help at all, table.remove needs a table to remove the object from, If no table is given, It throws an error.

Find ‘table.remove(Banned, UserId)’ at Script admin.
code:

table.remove(Banned, UserId)

change to

table.remove(table.find(Banned, UserId))

or

table.remove(Banned, table.find(Banned, UserId))

Try this:

table.remove(Banned, table.find(Banned, UserId))

No offense honestly but, are you copying my replies?

Yeah. try help him with code. If not work or error, something wrong in script with help us.

tried all of them, did not work

How is this list of banned users being saved? If it’s hardcoded, it won’t work because it will be removed, but won’t save for new servers or any other server.

Its a serverban, so its an empty table at first
then a userid is inserted via table.insert
and with the unban it will remove the user id of the user that is banned
but i have found no fix for it yet

Well I don’t know the answer but try to check the script of the HD Admin free model by @ForeverHD because it contains a working unban script.

doesnt the HD Admin unban use datastores?

Well, it looks like solutions on this post were right. Just change that code to this:

if table.find(Banned, UserId) then table.remove(Banned, table.find(Banned, UserId)) end

I don’t know, I just know that it works. Sorry maybe I don’t help you a lot :sweat_smile:

The user would not be in the server if they’re banned.

bruh, that will especially not work as the user is not in the game
so findfirstchild is NOT going to work

Try using one of the correct solutions here.

I will try your solution.
Maybe it will work

Here try this code:

remoteEvent2.OnServerEvent:Connect(function(player, Username, Reason, Type)
	local UserId = game.Players:GetUserIdFromNameAsync(Username)
	if table.find(Allowed, player.UserId) then
		if game.Players:FindFirstChild(Username)  and Type == "Kick" then
			game.Players:FindFirstChild(Username):Kick(Reason)
		elseif game.Players:FindFirstChild(Username) and Type=="Ban" then
			table.insert(Banned, game.Players:FindFirstChild(Username).UserId)
			game.Players:FindFirstChild(Username):Kick("You have been banned from this server. Reason: "..Reason)
		elseif game.Players:FindFirstChild(Username) and Type=="Unban" then
			local success, failure = pcall(function()
				if table.find(Banned, UserId) then table.remove(Banned, table.find(Banned, UserId)) end
				--table.remove(Banned, table.find(Banned, UserId))
			end)
			if success then
				remoteEvent4:FireClient(player, "Unban System","Unban successful!", 7.5)
			else
				remoteEvent4:FireClient(player, "Unban System","Unban failed! User was not found.", 7.5)
			end
		end
	elseif not table.find(Allowed, player.UserId) then
		table.insert(Banned, player.UserId)
		if Type=="Kick" then
			player:Kick("nice try "..Type.."ing someone ya big exploiter")
			Reason="Exploiting"
		else
			player:Kick("nice try "..Type.."ning someone ya big exploiter")
			Reason="Exploiting"
		end
	end
	serverbanreason=Reason
end)

Removed the pcall, and did some other fixing