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

Bad argument, removing elements from tables?

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago
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.

0
That worked, but now I have no output, and it doesn't end the round either way. systematicaddict 295 — 10y
0
Replace the line with alive[v.Name] = nil. Articulating 1335 — 10y
Ad

Answer this question