Class · inherits Instance
Team
About Team
The Team class represents a faction in a Roblox place. The only valid
parent for a Team is in the Teams service. Teams offer a range of
features that are useful to developers that can be divided into two rough
groups:
- Features that work 'out of the box'
- Features developers can program into their game.
Built-in Team Behavior
The following functionality of Teams exists by default and does not require the developer to program any custom behavior.
- When part of a Team, the name above a player's character
Modelwill be colored to theTeam.TeamColor - Changing
Player.TeamColorwill causePlayer.Teamto switch to the Team with the correspondingTeam.TeamColor - When using the default player list users will be grouped and displayed together as a team
- Setting
Player.Neutralto true will cause thePlayerto be disassociated with the team, but it will not changePlayer.TeamorPlayer.TeamColor - When a
Playerjoins a game, they will be allocated to the team withTeam.AutoAssignableset to true that has the fewest players. If no auto assignable team is available,Player.Neutralwill be set to true - When
SpawnLocation.Neutralis set to false, only players whosePlayer.TeamColormatchesSpawnLocation.TeamColorcan spawn on thatSpawnLocation - When
SpawnLocation.AllowTeamChangeOnTouchis set to true, a player'sPlayer.TeamColorwill change toSpawnLocation.TeamColorwhen their character touches theSpawnLocation
Optional Extended Team Behaviors
Many developers chose to add the following features to teams in their own code.
- Implement checks in weapon code to prevent friendly fire.
- Implement checks in doors or other features that allow only certain teams to use them
- Periodically reassign teams to maintain team balance
Properties 2
AutoAssignable
: booleanThis property determines whetherPlayerswill be automatically placed onto theTeamwhen joining. If multiple teams have this property set to true, Roblox will attempt to even the teams out whenPlayersare added.This property determines whether
Playerswill be automatically placed onto theTeamwhen joining. If multiple teams have this property set to true, Roblox will attempt to even the teams out whenPlayersare added.When a
Playerjoins a game they will be assigned to theTeamwithTeam.AutoAssignableset to true that has the fewest players. If no such team is available,Player.Neutralwill be set to true.Note while using this property will help even out teams when players are added, it will not do anything when players are removed. For this reason developers may wish to implement their own team balancing system.
TeamColor
: BrickColorThis property sets the color of theTeam. Determines thePlayer.TeamColorproperty of players who are a member of the team. Also determines the color displayed on the player list and above player's heads.This property sets the color of the
Team. Determines thePlayer.TeamColorproperty of players who are a member of the team.A lot of Roblox's default team functionality is based on the team color, rather than the name or object. For example,
SpawnLocationscan be assigned to a team viaSpawnLocation.TeamColor. For this reason it is recommended that developers ensure eachTeamhas a unique TeamColor.Any player which is a part of a team will have their name color changed to the team's TeamColor property. They will also be put underneath the team heading on the player list.
Methods 1
GetPlayers
() → List<Player>Returns a list ofPlayerswho are assigned to theTeam. APlayeris considered assigned if theirPlayer.Teamproperty is equal to theTeamandPlayer.Neutralis false.Returns a list of
Playerswho are assigned to theTeam. APlayeris considered assigned if theirPlayer.Teamproperty is equal to theTeamandPlayer.Neutralis false.This function has a number of potential uses, including counting the number of players on a
Teamor giving everyPlayeron aTeamaTool.
Events 2
PlayerAdded
Team.PlayerAdded:Connect(function(player))Fires whenever aPlayeris assigned to theTeam. A player is considered assigned if theirPlayer.Teamproperty is equal to theTeamandPlayer.Neutralis false.Fires whenever a
Playeris assigned to theTeam. A player is considered assigned if theirPlayer.Teamproperty is equal to theTeamandPlayer.Neutralis false.This event is team specific and will only fire when a
Playerjoints the specificTeam. Any function connected to this event will be passed thePlayerobject of the player who joined the team. For example:Team.PlayerAdded:Connect(function(player) print(player.Name.." has joined the team") end)PlayerRemoved
Team.PlayerRemoved:Connect(function(player))Fires whenever aPlayeris removed from aTeam. This can be due to thePlayerleaving the game,Player.Neutralbeing set to true or thePlayerjoining a different team.Fires whenever a
Playeris removed from aTeam. This can be due to thePlayerleaving the game,Player.Neutralbeing set to true or thePlayerjoining a different team.This event is team specific and will only fire when a
Playerleaves the specificTeam. Any function connected to this event will be passed thePlayerobject of the player who left the team. For example:Team.PlayerRemoved:Connect(function(player) print(player.Name.." has left the team") end)
Team also has every member of Instance. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.