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

How to Know when a team Reaches 0 players?

Asked by 6 years ago

I want it so when a player leaves a game it checks to see if a team has no players so it Clones a item. i have done this so far

   local players = team:GetPlayers()
game.Players.PlayerRemoving:connect(function(player)
    if game.Teams.Slot1.Players == 0 then
     game.Lighting.Start:Clone().Parent = game.Workspace
end
end

But i am no good with team

0
There are events for when a player leaves a team and joins the team User#5423 17 — 6y

1 answer

Log in to vote
0
Answered by
dispeller 200 Moderation Voter
6 years ago

I think you would have to create a function that loops through all the players and checks what team they are on.

Here is a simple one:

function getNumOfPlayersInTeam(BColor)
    local total = 0
    for i,v in pairs(game.Players:GetPlayers()) do
        if v.TeamColor == BColor then
            total = total + 1
        end
    end
    return total
end

so now, you would just do something like this:

if  getNumOfPlayersInTeam(game.Teams.Slot1.TeamColor) == 0 then
    -- bla bla bla
end
Ad

Answer this question