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

Bad argument, removing elements from tables?

I have a table, like this:

alive = {}

Then in my round script it sets a BoolValue, named InGame, inside every player, to true, then adds them to the table.

Then I want the round to end, so I have a for do loop:

		for time = 1,100 do
			wait(1)
			for i,v in pairs(game.Players:GetPlayers()) do
				if v.InGame.Value == false then
					table.remove(alive, v.Name)
				end
				if #alive <=1 then
					break
				elseif #alive == 0 then
					break
				end
			end
		end

But after I kill someone (I have a separate script that sets InGame to false when one dies), I get this error:

23:22:50.463 - Workspace.Rounds:115: bad argument #2 to 'remove' (number expected, got string)

The line it's referring to is the 5th line in my second script (the one that ends the round)

Please help?

1 answer

for time = 1,100 do
    wait(1)
    for i,v in pairs(game.Players:GetPlayers()) do
        if v.InGame.Value == false then
            table.remove(alive, i)
        end
        if #alive <=1 then
            break
        elseif #alive == 0 then
            break
        end
    end
end

the table.remove(x,y) function takes two parameters. X being the table you want to remove something from, and Y being the INDEX (Location) of the object you want to remove from the table.

2 comments

0

That worked, but now I have no output, and it doesn't end the round either way.

0

Replace the line with alive[v.Name] = nil.

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