Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

Code:

01local admins = {}
02local prefix = "!"
03local prefixlen = prefix:len()
04 
05game.Players.PlayerAdded:Connect(function(plr)
06     plr.Chatted:Connect(function(msg)
07        if msg:sub(1, 8 + prefixlen):lower() == prefix .. "unadmin " then
08            local TS = msg:sub(9 + prefixlen)
09            table.remove(admins, TS) -- error is here
10        end
11     end)
12end)

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

1 answer

Log in to vote
1
Answered by 4 years ago

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

1local Table1 = {
2"Test",
3"Dummy",
4"Stupid"
5}

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

1table.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!
Ad

Answer this question