Guides

How to Teleport Roblox Players to a Specific Public Server

LGSL Editorial PublisherJuly 19, 20262 min read

How to Teleport Roblox Players to a Specific Public Server

Roblox's TeleportService:TeleportAsync() accepts a destination place ID, an array of Player instances, and an optional TeleportOptions object. The method can only be called from a server script.

To target a particular public server, set TeleportOptions.ServerInstanceId to that server's valid instance ID and pass the options object to TeleportAsync():

local TeleportService = game:GetService("TeleportService")

local function teleportToPublicServer(players, destinationPlaceId, serverInstanceId)
    local options = Instance.new("TeleportOptions")
    options.ServerInstanceId = serverInstanceId

    local success, result = pcall(function()
        return TeleportService:TeleportAsync(
            destinationPlaceId,
            players,
            options
        )
    end)

    if not success then
        warn("TeleportAsync failed:", result)
    end

    return success, result
end

-- Supply an array even when teleporting one player.
teleportToPublicServer({ player }, destinationPlaceId, selectedServerInstanceId)

ServerInstanceId is the DataModel.JobId of the server instance to which the players should be teleported. If no specific server is supplied, Roblox sends the users to a public server and uses the first user in the player array for matchmaking.

Teleport requests involve network operations and can throw errors, so Roblox recommends wrapping them in pcall(). A request can also initiate without throwing an error and then fail before the player leaves the current server. TeleportService.TeleportInitFailed reports that failure:

local TeleportService = game:GetService("TeleportService")

TeleportService.TeleportInitFailed:Connect(function(
    player,
    teleportResult,
    errorMessage,
    targetPlaceId,
    teleportOptions
)
    warn(
        "Teleport failed:",
        player.Name,
        teleportResult.Name,
        errorMessage,
        targetPlaceId
    )
end)

TeleportService does not work during Roblox Studio playtesting. Publish the experience and test the teleport through the Roblox application.

L

Contributor at Live Game Server List covering multiplayer servers, hosting, latency, and gaming communities.