Collapse Sidebar




The private server id of the reserved server that the players are being teleported to. This field is populated only if the teleport is to a reserved server.

See also

For more information on how to teleport players between servers, take a look at the Telporting Between Places article.

Code Samples

Teleporting To a Reserved Server

The example below demonstrates how to use TeleportService/TeleportAsync to teleport a player to a reserved server and then save the TeleportAsyncResult/ReservedServerAccessCode to a datastore for later use to teleport other players to the same server. Saving off the access code is important because players cannot join reserved servers via the TeleportService without the reserved server access code.

Developers must save the reserved access code via GlobalDataStore|DataStores or some other location in order to keep it. For example, developers can create a DataStore for access codes and then save the reserved server access code as the value and the PrivateServerId as the key. By saving the access code to a datastore using the TeleportAsyncResult/PrivateServerId as the key, developers can get the server access code from within the reserved server and send it to other servers using the MessagingService.

For example, the MessagingService can be used as a part of an invitation system that allows players on a reserved server to invite players on different servers to their server. The reserved server access code can be sent using this service to be handled by a subscribed server containing the invited player. The invited player’s server can then handle the message and teleport the invited player using a TeleportAsync specifying the access code through the TeleportOptions/ReservedServerAccessCode property of the TeleportOptions.

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

local ServerAccessCodes = DataStoreService:GetDataStore("ReservedServerAccessCodes")

-- Teleport the player to a reserved server
local teleportOptions = Instance.new(“TeleportOptions”)
teleportOptions.ShouldReserveServer = true
local teleportResult = TeleportService:TeleportAsync(placeId, {player}, teleportOptions)

-- Save the ReservedServerAccessCode from the TeleportResult instance
ServerAccessCodes:SetAsync(teleportResult.PrivateServerId, teleportResult.ReservedServerAccessCode)

-- To retrieve the access code (can only be done from in the reserved server)
local accessCode = game.PrivateServerId ~= "" and ServerAccessCodes:GetAsync(game.PrivateServerId)