Service · inherits Instance
TeleportService
Enables transporting Players between places and servers. For
more information on how to teleport players between servers, see
Teleport between places.
About TeleportService
TeleportService is responsible for transporting Players
between different places and servers.
For more information on how to teleport players between servers, see Teleport between places.
Methods 9
GetArrivingTeleportGui
() → InstanceReturns the customLoadingScreen theLocalPlayerarrived into the place with.This function returns the customLoadingScreen the
LocalPlayerarrived into the place with.Note, the customLoadingScreen will not be used if the destination place is in a different game.
Loading Screen
During a teleport, while the destination place is loading, the customLoadingScreen is parented to the
CoreGui. Once the place has loaded theloading screenisparentedto nil.If you wish to preserve the customLoadingScreen and perform your own transitions, you will need to parent it to the local player's
PlayerGui. For an example of this, see the code sample below.Studio Limitation
Note that this service does not work during playtesting in Roblox Studio; to test aspects of your experience using it, you must publish the experience and play it in the Roblox application.
GetLocalPlayerTeleportData
() → VariantReturns the teleportData thePlayers.LocalPlayerarrived into the place with.This function returns the teleport data the
Players.LocalPlayerarrived with. It can only be called from the client.Exploiters can spoof teleport data. Send secure data such as player currency through a server-side service such as
DataStoreServiceto prevent tampering.GetPlayerPlaceInstanceAsync
(userId: User) → TupleYieldsReturns thePlaceIdandJobIdof the server the user with the givenUserIdis in provided it is in the same game as the current place.This function returns the
PlaceIdandJobIdof the server the user with the givenUserIdis in, provided it is in the same game as the current place.Then,
TeleportService.TeleportToPlaceInstancecan be called with this information to allow a user to join the target user's server.Upon a successful lookup, the function returns the following values:
If there is a problem during lookup, such as the user being offline, an error is thrown. It is recommended that you wrap calls to this function in
pcall.Limitations
You should be aware of the following limitations when using this function:
- This function can only be called by the server.
- This function may fail to return the correct information if the user is teleporting.
- It is possible for this function to throw an error, hence developers
should wrap it in a
LuaGlobals.pcall(see example below) - As this function returns the JobId of the server and not the access code
returned by
TeleportService.ReserveServerAsync, the ID returned is not appropriate for use with reserved servers.
Studio Limitation
Note that this service does not work during playtesting in Roblox Studio; to test aspects of your experience using it, you must publish the experience and play it in the Roblox application.
GetTeleportSetting
(setting: string) → VariantRetrieves a teleport setting saved usingTeleportService.SetTeleportSettingusing the given key.This function retrieves a teleport setting saved using
TeleportService.SetTeleportSettingusing the given key.This method is intended for use on the client only and should not be used on the server.
Teleport settings are preserved across teleportations within the same game. This means data can be saved using
TeleportService.SetTeleportSettingin one place and retrieved using GetTeleportSetting in another place the user has been teleported to.For example, in a game that allowed crouching you could save whether the user is currently crouching prior to teleporting as a teleport setting. This could then be retrieved in the destination place after the teleportation:
local TeleportService = game:GetService("TeleportService") local isCrouching = TeleportService:GetTeleportSetting("isCrouching")If no teleport setting exists under the given key, this function will return nil.
Differences from GlobalDataStores
Although they share some similarities, there are some key differences between teleport settings and datastores:
GlobalDataStore.SetAsyncstores the data on Roblox servers whereas SetTeleportSetting stores the data locally- Data stored in a
GlobalDataStoreis preserved after the user leaves the game universe whereas teleport settings are not GlobalDataStorescan only be accessed on the server, whereas teleport settings can only be accessed on the clientGlobalDataStoreshave usage limits, whereas teleport settings do not
In general teleport settings should be used to preserve client side information within a single play session across different places in a game.
GlobalDataStoresshould be used to save important player data that needs to be accessed across player sessions.Teleport settings and security
As teleport settings are stored locally, it is possible they can be manipulated by malicious users. This risk can be mitigated by employing server side validation.
Studio Limitation
Note that this service does not work during playtesting in Roblox Studio; to test aspects of your experience using it, you must publish the experience and play it in the Roblox application.
PromptExperienceDetailsAsync
(player: Player, universeId: int64) → PromptExperienceDetailsResultYieldsPrompts aPlayerwith information about the specified experience. The player can choose to teleport to the target experience through the prompt.Prompts the specified
Playerwith information of the specified experience. The prompt includes the experience name, creator name, maturity rating, etc. The prompt also includes a Join button which the player can use to be teleported to the target experience. If the player is ineligible to join the target experience, the button will be disabled.Any teleport failures after the player clicks the Join button will also fire
TeleportService.TeleportInitFailedproviding a reason for the failure.Limitations
- For security purposes, teleporting a user from your experience to another experience owned by others fails by default. See here for steps to enable cross-experience teleportation.
- This function currently can only be called from the client with
Players.LocalPlayeras theplayerparameter. - The join button will always be disabled during Studio playtesting; to test aspects of your experience using it, you must publish the experience and play it in the Roblox application.
ReserveServerAsync
(placeId: int64) → TupleYieldsReturns an access code that can be used to teleport players to a reserved server, along with theDataModel.PrivateServerIdfor it.This function returns an access code that can be used to teleport players to a reserved server, along with the server's
DataModel.PrivateServerId. It can only be called on the server.Reserved Servers
You can access reserved servers using:
TeleportService.TeleportAsyncwith theTeleportOptions.ReservedServerAccessCodeparameter.TeleportService.TeleportToPrivateServer, with the access codeReserveServerAsyncreturns.- A server is started when the access code is first used.
- Access codes remain valid indefinitely, meaning reserved servers can still be joined if no game server is running (in this case a new server will be started).
You can see if the current server is a reserved server by using the following code:
local isReserved = game.PrivateServerId ~= "" and game.PrivateServerOwnerId == 0The
DataModel.PrivateServerIdis constant across all server instances associated with the server access code, theDataModel.JobIdis not.Studio Limitation
Note that this service does not work during playtesting in Roblox Studio; to test aspects of your experience using it, you must publish the experience and play it in the Roblox application.
Cross-Platform Play
Players on Xbox and PlayStation with cross‑play disabled will arrive in a different server than players with cross‑play enabled. This can cause multiple game servers with the same
PrivateServerIdto exist. You can useDataModel.MatchmakingTypeto differentiate these game servers.SetTeleportGui
(gui: Instance) → ()Sets the customteleport GUIthat will be shown to the local user during teleportation, prior to the teleport being invoked.This function sets the custom
teleport GUIthat will be shown to the local user during teleportation, prior to the teleport being invoked.Note, the
teleport GUIwill not be used if the destination place is in a different game. It will also not persist across multiple teleports and will need to be set prior to each one.This function should only be used on the client. If the teleportation function is called from the server (as is the case with
TeleportService.TeleportAsync) then this function should be called on the client prior to this. One way of doing this is listening to aRemoteEventthat fires several seconds before teleportation.Loading screen
During a teleport, while the destination place is loading, the customLoadingScreen is parented to the
CoreGui. Once the place has loaded theloading screenisparentedto nil.This
ScreenGuican be fetched at the destination place usingTeleportService.GetArrivingTeleportGui, allowing you to parent it to thePlayerGuiand perform your own transitions.You are advised to also
parenttheScreenGuito thePlayerGuiin the start place while the teleport is initiating.External references
The teleport GUI and all of its descendants are carried to the destination place, but any property that references an
Instanceoutside the GUI's own tree is cleared during the teleport. For example, aSoundinside the GUI whoseSoundGrouppoints to aSoundGroupunderSoundServicewill arrive with that reference set tonil, because the target lives outside the GUI and cannot safely cross the boundary between servers.References that point to other instances within the GUI tree are preserved. If your loading screen depends on an external instance, recreate that instance inside the GUI tree.
Studio Limitation
Note that this service does not work during playtesting in Roblox Studio; to test aspects of your experience using it, you must publish the experience and play it in the Roblox application.
SetTeleportSetting
(setting: string, value: Variant) → ()Stores a value under a given key that persists across all teleportations in the same game.This function stores a value under a given key that persists across all teleportations in the same game.
This method is intended for use on the client only and should not be used on the server.
The stored value can later be retrieved using
TeleportService.GetTeleportSetting. This will work in the current place and any subsequent places thePlayers.LocalPlayerteleports to, provided they are in the same game.For example, in a game that allowed crouching you could save whether the user is currently crouching prior to teleporting as a teleport setting:
local TeleportService = game:GetService("TeleportService") local isCrouching = false TeleportService:SetTeleportSetting("isCrouching", isCrouching)The stored value may only contain value types. It cannot contain
Instancesor other types that reference engine state, as these cannot safely cross the boundary between servers.Allowed values:
- Primitives: a
bool, anumber, or astring - Value types such as
Vector3,CFrame,Color3,UDim2,NumberSequence,ColorSequence,Enumitems, and similar - A table without mixed keys (all strings or all integers) containing only the allowed types above
Not allowed (these will be removed before the teleport completes):
Instanceand instance referencesConnections,RBXScriptSignal, and functionsSharedTable- Types that reference engine or
DataModelstate, such asInputObject,RaycastParams, andRaycastResult
If a stored setting contains a disallowed type, that value is removed and an error is written to the developer console. Convert instance references to plain values (for example, a numeric ID or a string path).
If data is already stored under the given key, the previous value will be overwritten by the new value.
Differences from GlobalDataStores
Although they share some similarities, there are some key differences between teleport settings and datastores:
GlobalDataStore.SetAsyncstores the data on Roblox servers whereas SetTeleportSetting stores the data locally- Data stored in a
GlobalDataStoreis preserved after the user leaves the game universe whereas teleport settings are not GlobalDataStorescan only be accessed on the server, whereas teleport settings can only be accessed on the clientGlobalDataStoreshave usage limits, whereas teleport settings do not
In general teleport settings should be used to preserve client side information within a single play session across different places in a game.
GlobalDataStoresshould be used to save important player data that needs to be accessed across player sessions.Teleport settings and security
As teleport settings are stored locally, it is possible they can be manipulated by malicious users. This risk can be mitigated by employing server side validation.
Studio Limitation
Note that this service does not work during playtesting in Roblox Studio; to test aspects of your experience using it, you must publish the experience and play it in the Roblox application.
- Primitives: a
TeleportAsync
(placeId: int64, players: Instances, teleportOptions: Instance = nil) → InstanceYieldsThe all-encompassing method to teleport a player or group of players from one server to another.This function serves as the all-encompassing method to teleport a player or group of players from one server to another. It can be used to:
- Teleport players to a different place.
- Teleport players to a specific server.
- Teleport players to a reserved server.
Server-Only
This method can only be called from the server. If you need to initiate a teleport from the client, use a
RemoteEventto signal the server, then callTeleportService.TeleportAsyncfrom a serverScript. Client-side teleports usingTeleportService.Teleportis not recommended for new work. See Teleport between places for more information.Group Teleport Limitations
- Groups of players can only be teleported within a single experience.
- No more than 50 players can be teleported with a single
TeleportService.TeleportAsynccall.
Potential Errors
This is a list of potential reasons a teleport may fail, ranging from invalid teleports to network issues.
For more information on how to teleport players between servers and receive user data from a teleport, see Teleport between places.
Events 2
LocalPlayerArrivedFromTeleport
TeleportService.LocalPlayerArrivedFromTeleport:Connect(function(loadingGui, dataTable))Fires when theLocalPlayerenters the place following a teleport.This function fires when the
Players.LocalPlayerenters the place following a teleport. TheteleportDataandcustomLoadingScreenare provided as arguments.When fetching teleportData and the customLoadingScreen you are advised to use
TeleportService.GetLocalPlayerTeleportDataandTeleportService.GetArrivingTeleportGuiinstead. This is because these functions can be called immediately without having to wait for this event to fire.This event should be connected immediately in a
LocalScriptparented toReplicatedFirst. Otherwise, when the connection is made the event may have already fired.Loading Screen
During a teleport, while the destination place is loading, the customLoadingScreen is parented to the
CoreGui. Once the place has loaded theloading screenisparentedto nil.If you wish to preserve the customLoadingScreen and perform your own transitions, you will need to parent it to the local player's
PlayerGui. For example, using the following code inside aLocalScriptinReplicatedFirst:local TeleportService = game:GetService("TeleportService") local Players = game:GetService("Players") local ReplicatedFirst = game:GetService("ReplicatedFirst") TeleportService.LocalPlayerArrivedFromTeleport:Connect(function(customLoadingScreen, teleportData) local playerGui = Players.LocalPlayer:WaitForChild("PlayerGui") ReplicatedFirst:RemoveDefaultLoadingScreen() customLoadingScreen.Parent = playerGui -- animate screen here wait(5) -- destroy screen customLoadingScreen:Destroy() end)The customLoadingScreen will not be used if the destination place is in a different game.
Studio Limitation
Note that this service does not work during playtesting in Roblox Studio; to test aspects of your experience using it, you must publish the experience and play it in the Roblox application.
TeleportInitFailed
TeleportService.TeleportInitFailed:Connect(function(player, teleportResult, errorMessage, placeId, teleportOptions))Fires when a teleport fails to start, leaving the player in their current server.This event fires on both the client and the server when a request to teleport from a function such as
TeleportService.TeleportAsyncfails and the player does not leave the current server. It provides a reason for the failure, as well as all of the information necessary to retry the teleport. If a group teleport fails, the event will fire once per player.TeleportOptions
The
TeleportOptionsobject provided by this event is not identical to the one passed to the originalTeleportService.TeleportAsynccall. It is a new object populated with the necessary parameters to retry the teleport and send the player to the exact same destination. This is especially important for facilitating group teleports when they fail.For more information on how to teleport players between servers, see Teleport between places.
TeleportService also has every member of Instance. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.