API:Class/TeleportService/TeleportToPlaceInstance

TeleportToPlaceInstance

Function of ExplorerImageIndex70.pngTeleportService
void TeleportToPlaceInstance (
    int64 placeId,
    string instanceId,
    Player player = nil,
    string spawnName = "",
    Variant teleportData,
    ScreenGui customLoadingScreen = nil
)
Parameters:
  1. placeId
  2. instanceId
  3. player
  4. spawnName
  5. teleportData
  6. customLoadingScreen

Returns: void
Description: Will teleport the given player to a specific place instance given a placeId and an instanceId. Will error if attempted on a place instanceId not within the calling place's Game. 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.

Notes

  • The JobId property of the DataModel is the server's instanceId.
  • The teleportData parameter can be excluded, as Variants can be nil.

Example

When being used server-side the character needs to be specified. The below example assumes there's a player in your game named "Telamon".

local TeleportService = game:GetService("TeleportService")
local Success, Error, placeId, instanceId = TeleportService:GetPlayerPlaceInstanceAsync(1) 
 
if Success then 
    TeleportService:TeleportToPlaceInstance(placeId, instanceId, game.Players.Telamon)
else
    print(Error)
end

If using this client-side (LocalScript) then you would omit the usage of the third argument, and only provide the placeId and instanceId.

Tutorials Used In

TeleportService Guide

See Also

GetPlayerPlaceInstanceAsync