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 3 years ago
Edited 3 years ago

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

Log in to vote
1
Answered by 3 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

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!
Ad

Answer this question