Table.remove help

I have a serverban button with inputs and insert it using this:

table.insert(serverBans,tonumber(targetUser),"You have been server banned by "..tostring(submittedBy).." for: "..reason)

But how would I remove that? I can’t figure out how to use table.remove correctly as every time I’m trying it there isn’t any errors but it just doesn’t work.

you must have a table to insert on

I do have one to insert on, it works but I can’t remove it

table.remove(index number here) (I’m pretty sure) I almost never use tables /: Also, index numbers are pretty much numbers for each code seperation you have in your script. so for example

server bans is index 1 tonumber is index 2. it’s being seperated by the , you placed on each code inside the table.

Does doing table.remove(serverBans,target) not work? (you cant tonumber strings fyi just incase, unsure what targetUser is)

targerUser is the userid of the serverbanned person

that doesn’t work either, just tried it

Oh, I understand what you want now, I’m pretty sure you can do:
table.remove(serverbans, table.find(serverbans,tonumber(userid)))

1 Like

doesn’t work, no errors either

Eh, works for me, table.find returns the index of found userid, not sure what you’re doing, can you use prints and send me ur script and output?

	for i,v in pairs(serverBans) do
		if i == targetUser then
			print("user found")
			table.remove(serverBans, table.find(serverBans,i))
		end
	end

I’m using that to unban, it prints user found but doesn’t remove it

use this;

table.remove(serverBans, tonumber(targetUser))

already tried that as my first attempt

You can simply just find the index by using table.find, you don’t have to loop thru everything in there:
table.remove(serverBans, table.find(serverBans,tonumber(userid)))

table.find(serverBans,tonumber(userid)) returns index of userid in the table.

Here’s an example:
image

image

That just prints nil so I can’t do that

That means there’s no tonumber(userid) in the table…

table.insert(serverBans,tonumber(targetUser),"You have been server banned by "..tostring(submittedBy).." for: "..reason)

i use this to insert it into the table yet it says there isnt one but it manages to kick them if they’re part of the table but doesn’t remove it when you press unban

Can you print everything in the table after inserting?

It’s the userid then the reason for the ban

Well, can you see it in the output? U gotta make sure