I tried to remove a player with a variable of alien from a table called playersin as shown:
table.remove(playersin, alien)
(The Rest of the Script works perfectly fine)
The output shows me this:
16:58:55.598 - ServerScriptService.Game.G:148: bad argument #2 to 'remove' (number expected, got Object)
What does this mean?
The table.remove function only removes values from a list. It will not search through the table looking for the value to match the second argument. It looks for the key, which is suppose to be a number.
Example:
local list = { "pie", "ice cream", "candy", } table.remove(list, 2) -- this will remove "ice cream" because it's index value is 2.
If you want to make it so you remove a value from a table based on it's value, you can write a separate function that compares every value in the table to an argument you give it.
Like this:
local list = { "pie", "ice cream", "candy", } local function remove_value(Table, Value) for i,v in pairs (Table) do if v==Value then table.remove(Table,i) end end end remove_value(list, "pie") print(unpack(list)) -- > "ice cream" , "candy"