Teams
Summary
There can be different team modes in games, for example, players working together in a team to accomplish a goal (co-operative, team objective), or where all players are fighting against each other (deathmatch, free for all).
Players on opposite teams will have collision, but players on the same team will not have collision, so they will walk through each other. This is the only way to have collision for certain groups of players.
When creating a new project, the default mode will be Friendly. This means that players will not be able to apply damage to each other.
Team Settings
To change the team mode for a game, a Team Settings object can be added to the Hierarchy where the Team Mode can be changed. This can be found in Core Content, under Settings Objects.
Team Mode
On the Team Settings object, there is a drop down for the Team Mode that controls how players are assigned to teams.
Mode | Description |
---|---|
Free For All | Players are hostile to all other players. |
Team Versus | Player are assigned to teams that are hostile to each other. |
Friendly | Players are friendly to all other players. |
There can be a maximum of 4 teams with Team Versus mode, and each player that joins the game is randomly assigned to a team. This means that teams could become uneven due to it being random on what team the player is put on. This can be solved from Lua using a script, or using the Team Autobalance component.
Spawn Points
If the Team Mode on the Team Settings object is set to Team Versus, additional spawn points will be needed to create the teams (maximum of 4 teams). If only one spawn point is in the Hierarchy, or the Team property is the same for all spawn points, then all players will be on the same team.
See Spawn Points for more information.
Team Autobalancer
The Team Autobalancer component in Game Components will help split up players between the number of teams specified.
Property | Description |
---|---|
TeamCount | How many teams does this game have. We assume they are teams 1 through this number. |
MaxTeamSizeDifference | Team can be at most this different in size before players will get swapped if they are eligible. |
OnlySwitchDeadPlayers | Only switch players who are already dead. |
KillOnTeamSwitch | If we can swap live players, kill them when we do. |
ScrambleAtRoundEnd | Also scramble teams entirely t the end of the round. |
CoreMesh Team Settings
Meshes have a couple of properties that can be used with teams.
Property | Description |
---|---|
Team | A team number can be set which can be accessed from a script in Lua using the team property. |
Use Team Color | The color of the object will change to the color of the team the player is on. Blue for same team, red for enemy team. |
Enable Team Collision | If enabled, the object will have collision for players on the same team as the team property. |
Enable Enemy Collision | If enabled, the object will have collision for players on the enemy team. |
Example of detecting which team an object is on by accessing the team
property.
local MESH = script:GetCustomProperty("Mesh"):WaitForObject()
local DAMAGEABLE = MESH:FindAncestorByType("Damageable")
local function OnDamaged(obj, damage)
if Object.IsValid(damage.sourcePlayer) then
print("Object is on team:", MESH.team, "Player is on team:", damage.sourcePlayer.team)
end
end
if Object.IsValid(DAMAGEABLE) then
DAMAGEABLE.damagedEvent:Connect(OnDamaged)
end
Team Chat
The Game Settings object has settings to control how teams can communicate with each other.
Game Chat
The game chat category in the Properties panel has an option to change the Chat Mode. By default, this is set to Team and All.
Mode | Description |
---|---|
None | Chat is disabled and can't be used by players. |
Team Only | Only players on the same team can communicate with each other. |
Team and All | Players have the option to switch the channel between Team and All with Tab. |
All Only | All players can communicate with each other. |
Voice Chat
The voice chat category in the Properties panel has an option to change the Voice Chat Mode. By default this is set to All.
Mode | Description |
---|---|
None | Voice chat is disabled and can't be used by players. |
Team Only | Only players on the same team can communicate with each other using Voice Chat. |
All | All players in the game can communicate with each other using Voice Chat. |
Teams Namespace
The Teams namespace in the Lua API has some functions that can be used from a Lua script to determine if specific teams are enemies or friendly.
See the Teams namespace for more information.
Game Namespace
The Game namespace in the Lua API has functions that can be used to handle team scoring.
See the Game namespace for more information.
Player Object
The Player object in the Lua API has a team
property that can be accessed from a Lua script to retrieve the current team the player is on.
For example, getting the team the player is on when they join the game.
Game.playerJoinedEvent:Connect(function(player)
print("Player is on team:", player.team, player.name)
end)
See the Player object for more information.
Learn More
Spawn Points | Teams | Game | Player | Voice Chat