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

First element in an array is nil?

Asked by 3 years ago

I was making a program that finds whenever there's 1 person left alive, so here's the script:

local AlivePlrs = {}

    while #AlivePlrs ~= 1 do
        wait()
        for _, Char in pairs(game.Workspace:GetChildren()) do
            wait()
            if Char:IsA("Model") and Char:FindFirstChild("Humanoid") then -- Make sure it's a Character, not something else
                local Humanoid = Char.Humanoid
                table.insert(AlivePlrs, #AlivePlrs + 1, Char.Name)
                Humanoid.Died:connect(function() 
                    for Position, Plr in ipairs(AlivePlrs) do
                        wait()
                        if Plr == Char.Name then -- If they are in the table then...
                            table.remove(AlivePlrs, Position) -- Position is an iterator which gives a number, in this case we can use that number to find where their name is in this table and remove it
                        end
                    end
                end)
            end
        end
        wait()
    end

    print(AlivePlrs[1].Name)
    game.Workspace.Win:Fire(AlivePlrs[1])

There's an error message that AlivePlrs[1] is nil.

0
Are you sure you put any values inside the AlivePlrs array, if you do can you please show the full code Xapelize 2658 — 3y
0
This is the entire code, just runs until there's 1 player left Valkyrie1277 28 — 2y

Answer this question