# Source URL: https://dev.epicgames.com/documentation/en-us/uefn/triad-infiltration-7-balancing-players-during-the-game-in-verse
# Local doc: epic-docs/documentation/en-us/uefn/triad-infiltration-7-balancing-players-during-the-game-in-verse.md
# Section: Setting Up Player Join Functions
# Handles a new player joining the game.
OnPlayerAdded(InPlayer:player):void=
Logger.Print("A new Player joined, assigning them to a team")
FortTeamCollection := GetPlayspace().GetTeamCollection()
# Assign the new player to the smallest team, asymmetrically.
BalancePlayer(InPlayer)
for:
TeamIndex -> PlayerTeam:Teams
PlayerTeam = FortTeamCollection.GetTeam[InPlayer]
TeamTeleporter := Teleporters[TeamIndex]
Transform := TeamTeleporter.GetTransform()
do:
InPlayer.Respawn(Transform.Translation, Transform.Rotation)
Logger.Print("Teleported the spawned player to their start location")
# If the player was an infiltrator, call OnInfiltratorJoined in
# InvisibilityManager.
if(PlayerTeam = MaybeInfiltrators?):
InvisibilityManager.OnInfiltratorJoined(InPlayer)
Copy full snippet
Verse Library
verse
08 Setting Up Player Join Functions
Assigns players to teams, teleports them to spawn points, and triggers team join events.
extracted-snippets/documentation/en-us/uefn/triad-infiltration-7-balancing-players-during-the-game-in-verse/08-setting-up-player-join-functions.verse