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

TeleportInitFailed

This event fires if a request to teleport (from a function such as TeleportService/Teleport) fails and the player does not leave the current place server.

This event is fired on both the client and the server.

TeleportInitFailed includes a teleportResult argument (a Enum/TeleportResult enum) describing the reason the teleport failed along with the error message that is displayed to the user.

It is possible for teleportation to fail after the Player has left the place due to Roblox server issues. This event will not fire in this case and the user will be disconnected and required to rejoin.

Parameters

Name Type Default Description

The Player which failed to teleport

The Enum/TeleportResult describing the reason the teleport failed

The error message that is displayed to the user


Code Samples


Reattempt Failed Teleport

This code sample includes a function that will reattempt a teleport if Roblox servers are busy or an unexpected failure has occurred. It should be ran on the client.

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

local localPlayer = Players.LocalPlayer

local function localTeleportWithRetry(placeId, retryTime)
    local connection
    connection = TeleportService.TeleportInitFailed:Connect(function(player, teleportResult, errorMessage)
        if player == localPlayer then
            print("Teleport failed, TeleportResult: "..teleportResult.Name)
            -- check the teleportResult to ensure it is appropriate to retry
            if teleportResult == Enum.TeleportResult.Failiure or teleportResult == Enum.TeleportResult.Flooded then
                -- disconnect the connection
                connection:Disconnect()
                -- retry in retryTime seconds
                delay(retryTime, function()
                    print("Reattempting teleport")
                    TeleportService:Teleport(placeId)
                end)
            end
        end
    end)
    TeleportService:Teleport(placeId)
end

-- usage example:
local placeId = 1818 -- Crossroads
localTeleportWithRetry(placeId, 5)