Code:
01 | local admins = { } |
02 | local prefix = "!" |
03 | local prefixlen = prefix:len() |
04 |
05 | game.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 ) |
12 | end ) |
Anyone know why I'm getting the error invalid argument #2 to 'remove' (number expected, got string)
? All help is appreciated!
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
1 | local Table 1 = { |
2 | "Test" , |
3 | "Dummy" , |
4 | "Stupid" |
5 | } |
and you call table.remove(Table1, Test) it wont work, you have to index it.
1 | table.remove(Table 1 , [ 1 ] ) --this removes "Test" in the table, 1 is the index in this and Test == 1 Dummy == 2 and Stupid == 3, this will work! |