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

TeleportToPlaceInstance

This function teleports a Player to the place instance associated with the given placeId and instanceId. It can only be used to teleport to places in the same game.

The placeId is the DataModel/PlaceId of the server and the instanceId is the DataModel/JobId|JobId.

This function can not be used to teleport Player|Players to servers created using TeleportService/ReserveServer (reserved servers). For this, see TeleportService/TeleportToPrivateServer.

Spawn name

An optional spawnName parameter can be provided, which will cause the Player to initially spawn at the SpawnLocation of that name in 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.

Teleport data

A teleportData parameter can be specified. This is data the client will transmit to the destination place and can be retrieved using TeleportService/GetLocalPlayerTeleportData.

The teleportData can take any of the following forms:

  • A table without mixed keys (all keys are strings or integers)
  • A string
  • A number
  • A bool

As the teleportData is transmitted by the client it is not secure. For this reason it should only be used for local settings and not sensitive items (such as the users’ score or in-game currency).

If you need teleport data to persist across multiple teleports, you can use TeleportService/SetTeleportSetting and TeleportService/GetTeleportSetting.

Loading screen

A customLoadingScreen argument can be specified. This is a ScreenGui that is copied (without scripts) into the CoreGui of the destination place.

Note, TeleportService/SetTeleportGui is the preferred alternative to the customLoadingScreen argument as it can be called prior to the teleport.

The loading ScreenGui can be obtained in the destination place using TeleportService/GetArrivingTeleportGui, where developers can parent it to the PlayerGui.

Teleport failure

In some circumstances a teleport may fail. This can be due to the developer configuring the teleport incorrectly or issues with Roblox’s servers.

  • If a teleportation request is rejected the TeleportService/TeleportInitFailed event will fire the error message and a Enum/TeleportResult enumerator describing the issue
  • Teleports can fail ‘in transit’, after the user has left the server, due to issues with Roblox’s servers. In this case the user will be shown an error message and be required to rejoin the game

For more information on how to teleport players, see the Articles/Teleporting Between Places tutorial.

Parameters

Name Type Default Description

The ID of the place to teleport to

The DataMode/JobId of the server instance to teleport to

nil

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

Optional name of the SpawnLocation to spawn at

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


Following a Player in a Game Universe

The code sample below, when placed inside a Script in ServerScriptService will teleport users following another user to the place and server that user is in. Note, this will not work if the user is in a reserved server.

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    -- is this player following anyone?
    local followId = player.FollowUserId
    if followId then
        -- if so find out where they are
        pcall(function()
            local success, errorMessage, placeId, jobId = TeleportService:GetPlayerPlaceInstanceAsync(followId)
            -- have we found this player?
            if success then
                -- if so teleport
                TeleportService:TeleportToPlaceInstance(
                    placeId,
                    jobId,
                    player
                )
            end
        end)
    end
end)