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

Why isn't this working?

Asked by 9 years ago

So what I want it to do is then a player in _G.Survivors dies it removes them. The problem with this is when the _G.Survivors[1] player dies it removes everyone from the table. Here's my code:

_G.Survivors = {}

for a,b in pairs(game.Players:GetChildren()) do
    table.insert(_G.Survivors,b)
    local id = Instance.new("IntValue",b)
    id.Name = "Survivor" -- Just to mark that the player is a survivor
end

for a,b in pairs(game.Players:GetChildren()) do
    coroutine.resume(coroutine.create(function()
        while wait() do
            if b.Character:FindFirstChild("Survivor") then
                if b.Character.Humanoid.Health == 0 then
                    survivorDied(b)
                end
            end
        end
    end))
end

function survivorDied(p)
    for a,b in pairs(_G.Survivors) do
        wait()
        if p.Name == b.Name then 
            table.remove(_G.Survivors,a)
        end
    end
end

Thanks!

Answer this question