Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to Know when a team Reaches 0 players?

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

1 comment

0

There are events for when a player leaves a team and joins the team

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.