TeleportService

Visualizza obsoleti
Non costruibile
Assistenza

TeleportService is responsible for transporting Players between different places and servers.

For more information on how to teleport players between servers, see Teleporting Between Places.

Sommario

Metodi

Eventi

Proprietà

Metodi

GetArrivingTeleportGui


Restituzioni

Campioni di codice

Gestire una GUI di caricamento del teletrasporto

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local customLoadingScreen = TeleportService:GetArrivingTeleportGui()
if customLoadingScreen then
local playerGui = Players.LocalPlayer:WaitForChild("PlayerGui")
ReplicatedFirst:RemoveDefaultLoadingScreen()
customLoadingScreen.Parent = playerGui
task.wait(5)
customLoadingScreen:Destroy()
end

GetLocalPlayerTeleportData

Variant

Restituzioni

Variant

Campioni di codice

Getting LocalPlayer Teleport Data

local TeleportService = game:GetService("TeleportService")
local teleportData = TeleportService:GetLocalPlayerTeleportData()
print("Local player arrived with this data:", teleportData)

GetPlayerPlaceInstanceAsync

Resa

Parametri

userId: number

Restituzioni

Campioni di codice

Following Another Player

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
-- Is this player following anyone?
local followId = player.FollowUserId
-- If so, find out where they are
if followId and followId ~= 0 then
local _currentInstance, placeId, jobId
local success, errorMessage, _currentInstance, placeId, jobId = pcall(function()
-- followId is the user ID of the player that you want to retrieve the place and job ID for
return TeleportService:GetPlayerPlaceInstanceAsync(followId)
end)
if success then
-- Teleport player
TeleportService:TeleportToPlaceInstance(placeId, jobId, player)
else
warn(errorMessage)
end
else
warn("Player " .. player.UserId .. " is not following another player!")
end
end)

GetTeleportSetting

Variant

Parametri

setting: string

Restituzioni

Variant

ReserveServer

Resa

Parametri

placeId: number

Restituzioni

Campioni di codice

TeleportService: Teleport to a Reserved Server

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local code = TeleportService:ReserveServer(game.PlaceId)
local players = Players:GetPlayers()
TeleportService:TeleportToPrivateServer(game.PlaceId, code, players)
-- You could add extra arguments to this function: spawnName, teleportData and customLoadingScreen
TeleportService: Teleport to a Reserved Server via Chat

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetGlobalDataStore()
-- Get the saved code
local code = dataStore:GetAsync("ReservedServer")
if typeof(code) ~= "string" then -- None saved, create one
code = TeleportService:ReserveServer(game.PlaceId)
dataStore:SetAsync("ReservedServer", code)
end
local function joined(player)
player.Chatted:Connect(function(message)
if message == "reserved" then
TeleportService:TeleportToPrivateServer(game.PlaceId, code, { player })
end
end)
end
Players.PlayerAdded:Connect(joined)

SetTeleportGui

()

Parametri


Restituzioni

()

Campioni di codice

Teletrasporto del giocatore locale

local TeleportService = game:GetService("TeleportService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local playerGui = Players.LocalPlayer:WaitForChild("PlayerGui")
local PLACE_ID = 0 -- sostituisci qui
local loadingGui = ReplicatedStorage:FindFirstChild("LoadingGui")
-- genitore della gui di caricamento per questo posto
loadingGui.Parent = playerGui
-- imposta l'interfaccia utente di caricamento per il luogo di destinazione
TeleportService:SetTeleportGui(loadingGui)
TeleportService:Teleport(PLACE_ID)

SetTeleportSetting

()

Parametri

setting: string
value: Variant

Restituzioni

()

Teleport

()

Parametri

placeId: number
player: Instance
Valore predefinito: "nil"
teleportData: Variant
customLoadingScreen: Instance
Valore predefinito: "nil"

Restituzioni

()

Campioni di codice

Teletrasporto del giocatore locale

local TeleportService = game:GetService("TeleportService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local playerGui = Players.LocalPlayer:WaitForChild("PlayerGui")
local PLACE_ID = 0 -- sostituisci qui
local loadingGui = ReplicatedStorage:FindFirstChild("LoadingGui")
-- genitore della gui di caricamento per questo posto
loadingGui.Parent = playerGui
-- imposta l'interfaccia utente di caricamento per il luogo di destinazione
TeleportService:SetTeleportGui(loadingGui)
TeleportService:Teleport(PLACE_ID)
Teleporting from the server

local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local PLACE_ID = 0 -- replace here
local USER_ID = 1 -- replace with player's UserId
local player = Players:GetPlayerByUserId(USER_ID)
TeleportService:Teleport(PLACE_ID, player)

TeleportAsync

Resa

Parametri

placeId: number
players: Instances
teleportOptions: Instance
Valore predefinito: "nil"

Restituzioni

TeleportPartyAsync

Resa

Parametri

placeId: number
players: Instances
teleportData: Variant
customLoadingScreen: Instance
Valore predefinito: "nil"

Restituzioni

Campioni di codice

Teleport all players in the server

local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local PLACE_ID = 0 -- replace
local playerList = Players:GetPlayers()
local success, result = pcall(function()
return TeleportService:TeleportPartyAsync(PLACE_ID, playerList)
end)
if success then
local jobId = result
print("Players teleported to", jobId)
else
warn(result)
end

TeleportToPlaceInstance

()

Parametri

placeId: number
instanceId: string
player: Instance
Valore predefinito: "nil"
spawnName: string
teleportData: Variant
customLoadingScreen: Instance
Valore predefinito: "nil"

Restituzioni

()

Campioni di codice

Following Another Player

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
-- Is this player following anyone?
local followId = player.FollowUserId
-- If so, find out where they are
if followId and followId ~= 0 then
local _currentInstance, placeId, jobId
local success, errorMessage, _currentInstance, placeId, jobId = pcall(function()
-- followId is the user ID of the player that you want to retrieve the place and job ID for
return TeleportService:GetPlayerPlaceInstanceAsync(followId)
end)
if success then
-- Teleport player
TeleportService:TeleportToPlaceInstance(placeId, jobId, player)
else
warn(errorMessage)
end
else
warn("Player " .. player.UserId .. " is not following another player!")
end
end)

TeleportToPrivateServer

()

Parametri

placeId: number
reservedServerAccessCode: string
players: Instances
spawnName: string
teleportData: Variant
customLoadingScreen: Instance
Valore predefinito: "nil"

Restituzioni

()

Campioni di codice

TeleportService: Teleport to a Reserved Server via Chat

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetGlobalDataStore()
-- Get the saved code
local code = dataStore:GetAsync("ReservedServer")
if typeof(code) ~= "string" then -- None saved, create one
code = TeleportService:ReserveServer(game.PlaceId)
dataStore:SetAsync("ReservedServer", code)
end
local function joined(player)
player.Chatted:Connect(function(message)
if message == "reserved" then
TeleportService:TeleportToPrivateServer(game.PlaceId, code, { player })
end
end)
end
Players.PlayerAdded:Connect(joined)
TeleportService: Teleport to a Reserved Server

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local code = TeleportService:ReserveServer(game.PlaceId)
local players = Players:GetPlayers()
TeleportService:TeleportToPrivateServer(game.PlaceId, code, players)
-- You could add extra arguments to this function: spawnName, teleportData and customLoadingScreen

TeleportToSpawnByName

()

Parametri

placeId: number
spawnName: string
player: Instance
Valore predefinito: "nil"
teleportData: Variant
customLoadingScreen: Instance
Valore predefinito: "nil"

Restituzioni

()

Campioni di codice

TeleportService:TeleportToSpawnByName

local TeleportService = game:GetService("TeleportService")
TeleportService:TeleportToSpawnByName(1818, "TeleportSpawn")

Eventi

LocalPlayerArrivedFromTeleport

Parametri

loadingGui: Instance
dataTable: Variant

TeleportInitFailed

Parametri

player: Instance
teleportResult: Enum.TeleportResult
errorMessage: string
placeId: number
teleportOptions: Instance