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

[table] table.remove problem?

My error : bad argument #2 to 'remove' (number expected, got table)

Settings = {
	Ranked = { -- 3=Owner, 2=Admin, 1=Member, 0=nil, -.5=Muted, -1=Banned
		{Name = "Player",Rank = 3};
		{Name = "Idiot",Rank = -.5};
	},
}

for _,v in pairs(Settings.Ranked) do
	local msg = msg:lower()
	local sub = msg:sub(7)		
	local data = v.Name:lower()
	local num = tonumber(-.5)
	if msg == 'all' and v.Rank == num or data:find(sub) and v.Rank == num then
		table.remove(Settings.Ranked, v) -- Error here
	end
end 

1 comment

0

I tryed v[1] but it wouldnt remove the correct ban.

1 answer

✓ Accepted answer

v refers to the rank data. _ refers to the key/index. The simple solution to that would be replacing table.remove(Settings.Ranked, v) by table.remove(Settings.Ranked, _), but that messes everything up because it's in the middle of a loop. Instead, if you don't want any holes inside the table indices (it may be better to use the rank info as the key itself instead and simply set the value to true, but it may be a bit late for that now), you could try doing this:

local temp = {}
for _,v in pairs(Settings.Ranked) do
    local msg = msg:lower()
    local sub = msg:sub(7)      
    local data = v.Name:lower()
    local num = tonumber(-.5)
    if msg == 'all' and v.Rank == num or data:find(sub) and v.Rank == num then
        temp[#temp + 1] = _
    end
end
for i,v in ipairs(temp) do
    table.remove(Settings.Ranked, v + 1 - i) -- `+ 1 - i` is to accomodate for the removed indices.
end

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