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

How to make a when all players in team dies will run next code?

Asked by
Diltz_3 75
6 years ago

I want to make script when all players in team dies will be run next code, when I tried I'm tested and code starts if one player will die in team not all what's my mistake?

ServerScript

01for i,b in pairs(game.Teams.Playing:GetPlayers()) do
02    b.Character:FindFirstChild("Humanoid").Died:connect(function()
03        wait(8)
04        workspace.Map:ClearAllChildren()
05        if Players.Value < 2 then
06            Message.Value = "2 Players are needed!"
07            GameActive = false
08        else
09            gamestart()
10            Message.Value = "Intermission..."
11        end
12    end)
13end

1 answer

Log in to vote
0
Answered by
fredfishy 833 Moderation Voter
6 years ago

Something like this should work?

Basically, your problem is that your event fires when ANY humanoid dies. You need to keep track of how many there are, decrement a counter when somebody dies, and when there are 0 remaining, the team is eliminated.

01function checkEliminated(counter, team)
02    if counter.Value <= 0 then
03        -- team eliminated
04    end
05end
06 
07function beginRound()
08    for _, team in pairs(game:GetService("Teams"):GetChildren()) do
09        if team:IsA("Team") then
10            -- Create a global counter of remaining players in a team
11            local aliveCounter = Instance.new("IntValue", team)
12            aliveCounter.Name = "PlayersRemainingCount"
13 
14            -- Get all the players in this team
15            local teamPlayers = team:GetPlayers()
View all 34 lines...
Ad

Answer this question