PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

TeleportToSpawnByName

This function behaves the same as TeleportService/Teleport with the exception that it includes a spawnName parameter, causing the Player to spawn at the SpawnLocation of that name at the destination place.

The SpawnLocation must be valid for the Player to spawn on. For example, it must be SpawnLocation/Neutral|neutral or set to the same SpawnLocation/TeamColor|TeamColor as the Team the Player will be assigned to upon joining the game.

The Player will still spawn at the correct SpawnLocation even the teleport is to a place in a different universe. The spawn will also be correct if Players/CharacterAutoLoads is false in the destination place and the Player/Character|Character is loaded manually using Player/LoadCharacter|LoadCharacter.

The teleportation will only affect the SpawnLocation used initially. If the Player respawns again subsequently it will not necessarily be at this SpawnLocation.

For more information about teleporting please see TeleportService/Teleport or the Articles/Teleporting Between Places tutorial.

Parameters

Name Type Default Description

The ID of the place to teleport to

The name of the SpawnLocation to spawn at

nil

The Player to teleport, if this function is being called from the client this defaults to the Players/LocalPlayer

Optional data to be passed to the destination place. Can be retrieved using TeleportService/GetLocalPlayerTeleportData

nil

Optional custom loading screen to be placed in the CoreGui at the destination place. Can be retrieved using TeleportService/GetArrivingTeleportGui

Returns

Return Type Summary

Code Samples


TeleportService:TeleportToSpawnByName

This code will teleport a player to Crossroads, and if there is a spawn named “TeleportSpawn” then the player would spawn on it. This assumes it’s being used in a /LocalScript.

game:GetService('TeleportService'):TeleportToSpawnByName(1818, "TeleportSpawn")