Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

Code:

local admins = {}
local prefix = "!"
local prefixlen = prefix:len()

game.Players.PlayerAdded:Connect(function(plr)
     plr.Chatted:Connect(function(msg)
		if msg:sub(1, 8 + prefixlen):lower() == prefix .. "unadmin " then
			local TS = msg:sub(9 + prefixlen)
			table.remove(admins, TS) -- error is here
		end
     end)
end)

Anyone know why I'm getting the error invalid argument #2 to 'remove' (number expected, got string)? All help is appreciated!

1 answer

✓ Accepted answer

When you remove something in a using a remove, it has to be a number, you can't remove a string. TS is a string because it is a msg. table's and their keywords must have args passed as you know. say we have a table

local Table1 = {
"Test",
"Dummy",
"Stupid"
}

and you call table.remove(Table1, Test) it wont work, you have to index it.

table.remove(Table1, [1]) --this removes "Test" in the table, 1 is the index in this and Test == 1 Dummy == 2 and Stupid == 3, this will work!

This discussion is preserved as it was. New answers, comments, and votes are closed.