API:Class/TeleportService/TeleportToSpawnByName

TeleportToSpawnByName

Function of ExplorerImageIndex70.pngTeleportService
void TeleportToSpawnByName (
    int placeId,
    string spawnName,
    Player player = nil,
    Variant teleportData,
    ScreenGui customLoadingScreen = nil
)
Parameters:
  1. placeId
    • Type: int
    • Required
  2. spawnName
  3. player
  4. teleportData
  5. customLoadingScreen

Returns: void
Description: Teleports someone like Teleport, but has a second argument allowing someone to teleport to a certain spawn. However, the spawn must have its Neutral property set to true. The given teleportData can be any value that can be stored in a datastore, and will be transported along with the player. The customLoadingScreen is a GUI that'll be made static (scripts don't run, TweenPosition etc doesn't work, ...) and displayed during teleporting. You can see these arguments after the player has been teleported, using LocalPlayerArrivedFromTeleport.

Example

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")

The below does the same as the code shown above, but from a Script. It assumes that there's a Player named 'Telamon'.

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

Tutorials Used In

TeleportService Guide