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

Action activates when all players but 1 die?

Asked by 10 years ago

So, i can't figure out how this would work.... the title says it all. I have a variable that holds all the players and a killer variable that represents a player that was randomly chosen from the Players variable/table.

Would i use a Died event? IDK!

0
By Died event you mean CharacterRemoving.So every time a Player is dead remove their name from the table until you have  one  player name in the table. Kozero 120 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago

Make an alive variable inside the players, and create a separate script to handle switching it off when their Humanoid.Died

Then create a table, like alive = {}

alive = {}
--later in the script
        for i,v in pairs(game.Players:GetPlayers()) do
            if v:FindFirstChild("Alive") then
                v.Alive.Value = true
                table.insert(alive, v.Name)
            end
        end
--this is the part to end it If only one player is alive
        for time = 1,120 do 
            wait(1) 
            if #alive <= 1 then
                break
            end 
            for i,v in pairs(game.Players:GetPlayers()) do 
                if not v.Alive.Value then 
                    table.remove(alive, i)
                end 
            end 
        end 

This is just an example of how I do it.

0
Inside the Players variable or game.Players? RobloxHelper49 55 — 10y
Ad
Log in to vote
-1
Answered by
war8989 35
10 years ago

Yes, you would use a Died event, and the variable that holds the players should be a table. Whenever a player dies, you would remove them from the table, and after a player dies you should check the length of the table that holds the players and see if the length is equal to one, if so, do your action.

Answer this question