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

How to make a script recognize when all players have died?

Asked by
reaper5 10
10 years ago

Such as Murder Mystery when all Innocents have died the game restarts. I do not know the process of that, anyone care to explain/demonstrate?

( I have the code thought out I just am struggling on figured this bit out. Any help would be appreciated)

1 answer

Log in to vote
2
Answered by
Dummiez 360 Moderation Voter
10 years ago

You would probably need a loop to set all values to true when the game starts:

local p = game.Players:GetPlayers()
for i = 1, #p do
    p[i].Alive.Value = true
    print(player.Name .. " is alive.")
end

And while the game is playing:

game:GetService('Players').PlayerAdded:connect(function(player)

local isAlive = Instance.new("BoolValue")
isAlive.Name = "Alive"
isAlive.Value = false
isAlive.Parent = player

    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            print(player.Name .. " has died!")
            player.Alive.Value = false

            local numPlrAlive = 0
            local p = game.Players:GetPlayers()

                for i = 1, #p do
                    if p[i].Alive.Value then
                        print(player.Name .. " is still alive!")
                        numPlrAlive = numPlrAlive + 1
                    end
                end

            if numPlrAlive > 0 then
                print("Players are still alive")
            else
                print("Everyone is dead!")
            end

        end)
    end)
end)
0
Thanks reaper5 10 — 10y
0
+1 reaper5 10 — 10y
Ad

Answer this question