Invalid argument #2 to 'remove' (number expected, got string)

what I’m trying to do is have two identical tables (so I can keep the original table, and remove values from the other one)

ERROR: “invalid argument #2 to ‘remove’ (number expected, got string)”

here is the two tables I used:

local Surfaces = {
"Top",
"Bottom",
"Left",
"Right",
"Front",
"Back"
}

local Rem_Surface = {
"Top",
"Bottom",
"Left",
"Right",
"Front",
"Back"
}

and here is where I remove one of the values:

local surface = Mouse.TargetSurface

for i, v in pairs(Surfaces) do
	if surface.Name == v then
		table.remove(Rem_Surface,v)
	end
end

I can’t seem to find the issue, any help is appreciated!

table.remove takes an index to remove, not the value.

- table.remove(Rem_Surface,v)
+ table.remove(Rem_Surface, i)
1 Like

Along with what @sjr04 said, it is also good practice to break the loop after the removal too, otherwise you waste CPU cycles scanning over nothing necessary:

local surface = Mouse.TargetSurface

for i, v in pairs(Surfaces) do
	if surface.Name == v then
		table.remove(Rem_Surface, i)
		break
	end
end
1 Like

That makes sense, thank you for that!

1 Like