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

Detect when all players have died?

Asked by 8 years ago

I posted this yesterday but I did not get a response on how to do it but how to keep exploiters from chaining the value.

How would I make a script that once all player have died the game will end? I rather not use values but use a table and remove each player. I am just not sure how to make the table and remove the players.

Thanks, Game

2 answers

Log in to vote
0
Answered by
Link150 1355 Badge of Merit Moderation Voter
8 years ago
Edited 8 years ago

To detect if someone died, you would use the Died event of Humanoid objects.

-- We declare a variable 't' to hold our table. It is initially empty.
local t = {}

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        local humanoid = character:WaitForChild("Humanoid")

        humanoid.Died:connect(function()
            -- Oops. Someone died. We add them to the table.
            table.insert(t, player)
        end)
    end)
end)

To check if everyone is dead, it is simply a matter of looping through all connected players and see if someone is missing in the table:

local function isEveryoneDead()
    for _, v in pairs(game.Players:GetPlayers()) do
        if not t[v] then
            -- A player is not in the table.

            return false
        end
    end

    -- All players are dead.
    return true
end

-- [...]

if isEveryoneDead() then
    -- If everyone is dead then empty the table and react appropriately.

    t = {}
end

Hope this helped. If it did, please make sure to mark my answer as accepted and optionally upvote; It helps both of us. :)

Ad
Log in to vote
0
Answered by 8 years ago

Well, Alot of help is on youtube also. Maybe you should look up humanoids. If all players health reaches 0, the game will end. You can ask more questions about different things involved in this question. I hope this helped.

0
^ Ok, but I would not be asking if I found something. MisterThackeryBinx 29 — 8y

Answer this question