Is there a way to find usernames of players in a team?

I am currently making a new game and I am trying to find a way if I can find usernames in a team. Not the number of people in the team but usernames.

2 Likes
local Players = Teams.TeamName:GetPlayers()

That will give you a list of all the players in the team. You can print the name of the players by doing

for _, Player in pairs(Players) do
   print(Player.Name)
end
12 Likes

There are events for when a player is added / removed from the team. What is this going to be used for?

You forgotten to make a variable for Teams.

local Teams = game:GetService("Teams")

I assume that the retrieval of the Teams service was implied, since its indexing is required to actually do anything with teams (bar any other properties that reference Team instances). More of a minor concern than anything, but good to note anyway.

2 Likes

As Colbert said, Teams / Players as a variable is implied.

1 Like

If you’ve got a solution from this post then please make whoever helped you as the solution.

I’ve always just run a loop through the current players and added them to a table if their teamcolor matched what I was looking for.

local teams = game:GetService('Teams')

for _, player in pairs(teams['Name of Team']:GetPlayers()) do
    print(player.Name)
end
1 Like

@colbert2677 @Kymaraaa Just making sure :slightly_smiling_face: