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

How to get the amount of players on a team? [UNANSWERED]

I need a script that waits until there is only 1 player on team Bright Blue ad then show a GUI in Game.Workspace.ScreenGui.WinnerGUI for 20 seconds, then make in invisible once again. Help is really appreciated! -Anth4598

1 answer

Loop through each player and if they're on a given team, increase a counter by one. I'd make a function like this for it.

function teamCount( team )
	local c = 0
	local team = type(team) == "string" and BrickColor.new(team) or team
	for _, plr in pairs(Game:GetService("Players"):GetPlayers()) do
		if plr.TeamColor == team then
			c = c + 1
		end
	end
	return c
end

print("#Players on Bright red: " .. teamCount("Bright red"))
-- Alternatively
print("#Players on Bright blue: " .. teamCount(BrickColor.new("Bright blue")))

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