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

SetTeleportGui

This function sets the custom ScreenGui|teleport GUI that will be shown to the local user during teleportation, prior to the teleport being invoked.

Note, the ScreenGui|teleport GUI will 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/TeleportPartyAsync) then this function should be called on the client prior to this. One way of doing this is listening to a RemoteEvent that fires several seconds before teleportation.

-- Client

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

local localPlayer = Players.LocalPlayer
local teleportGui = Instance.new("ScreenGui") -- for demonstration purposes

-- this RemoteEvent needs to be created on the server and fired before teleporting
local teleportEvent = ReplicatedStorage:WaitForChild("TeleportPrepare")

-- set the teleport gui so we are ready
TeleportService:SetTeleportGui(teleportGui)

teleportEvent.OnClientEvent:Connect(function()
    -- show the gui prior to the teleport
    local playerGui = localPlayer:WaitForChild("PlayerGui")
    teleportGui.Parent = playerGui
end)

Loading screen

During a teleport, whilst the destination place is loading, the customLoadingScreen is parented to the CoreGui. Once the place has loaded the ScreenGui|loading screen is Instance/Parent|parented to nil.

This ScreenGui can be fetched at the destination place using TeleportService/GetArrivingTeleportGui, allowing you to parent it to the PlayerGui and perform your own transitions.

You are advised to also Instance/Parent|parent the ScreenGui to the PlayerGui in the start place whilst the teleport is initiating.

Parameters

Name Type Default Description

gui

The loading `ScreenGui` that is to be displayed during teleportation

Returns

Return Type Summary
This function does not return anything!

Code Samples


Teleporting the local player

This snippet demonstrates how TeleportService can be used to teleport the Players/LocalPlayer|LocalPlayer from the client.

It also shows how TeleportService/SetTeleportGui can be used to define a custom loading GUI. Note, this ScreenGui will need to be retrieved at the destination place using TeleportService/GetArrivingTeleportGui and be parented to the PlayerGui.

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

local playerGui = Players.LocalPlayer:WaitForChild("PlayerGui")

local placeId = 0 -- replace here
local loadingGui = ReplicatedStorage:FindFirstChild("LoadingGui") -- replace here

-- parent the loading gui for this place
loadingGui.Parent = playerGui

-- set the loading gui for the destination place
TeleportService:SetTeleportGui(loadingGui)

-- teleport the user
TeleportService:Teleport(placeId)