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

Is it possible to return a list of names on a team?

I'm attempting to make a GUI where it shows the members of a team. Is it possible to do this with the following?

local Teams = game.Teams:GetTeams()

local ExampleTeam = Teams:FindFirstChild("ExampleTeam")

local TeamMembers = ExampleTeam:GetChildren()

1 answer

It is possible, but it is slightly more involved then calling a single method.

In order to accomplish this, you'll need to loop through all the players in the game and check to see what value their property TeamColor holds. If it is the same as the color of the Team you are counting, then you increment a counter variable by 1. Once you have gone through all of the players, the counter variable will be equal to the number of players on the team.

####Example:

local function countTeamPlayers(teamColor)
	local numPlayers = 0
	for _, player in next, game.Players:GetPlayers() do
		if player.TeamColor == teamColor then
			numPlayers = numPlayers + 1
		end
	end
	return numPlayers
end

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