Classe motore
TeleportService
*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.
Sommario
Proprietà
Metodi
GetLocalPlayerTeleportData():Variant |
GetPlayerPlaceInstanceAsync(userId: User):Tuple |
GetTeleportSetting(setting: string):Variant |
PromptExperienceDetailsAsync(player: Player,universeId: number):Enum.PromptExperienceDetailsResult |
ReserveServer(placeId: number):Tuple |
ReserveServerAsync(placeId: number):Tuple |
SetTeleportGui(gui: Instance):() |
SetTeleportSetting(setting: string,value: Variant):() |
TeleportAsync(placeId: number,players: Instances,teleportOptions: Instance):Instance |
TeleportPartyAsync(placeId: number,players: Instances,teleportData: Variant,customLoadingScreen: Instance):string |
TeleportToPrivateServer(placeId: number,reservedServerAccessCode: string,players: Instances,spawnName: string,teleportData: Variant,customLoadingScreen: Instance):() |
TeleportToSpawnByName(placeId: number,spawnName: string,player: Instance,teleportData: Variant,customLoadingScreen: Instance):() |
Eventi
LocalPlayerArrivedFromTeleport(loadingGui: Instance,dataTable: Variant):RBXScriptSignal |
TeleportInitFailed(player: Instance,teleportResult: Enum.TeleportResult,errorMessage: string,placeId: number,teleportOptions: Instance):RBXScriptSignal |
Riferimento API
Proprietà
CustomizedTeleportUI
Metodi
GetArrivingTeleportGui
Restituzioni
Campioni di codice
Gestione di un GUI di Caricamento 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()
endGetLocalPlayerTeleportData
TeleportService:GetLocalPlayerTeleportData():Variant
Restituzioni
Variant
Campioni di codice
Ottenere i dati di teletrasporto del LocalPlayer
local TeleportService = game:GetService("TeleportService")
local teleportData = TeleportService:GetLocalPlayerTeleportData()
print("Il giocatore locale è arrivato con questi dati:", teleportData)GetPlayerPlaceInstanceAsync
Parametri
Restituzioni
Campioni di codice
Seguire un altro giocatore
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local followId = player.FollowUserId
if followId and followId ~= 0 then
-- Questo giocatore sta seguendo qualcun altro? In tal caso, scopri dove si trova
local success, currentInstance, error, placeId, jobIdOrErr = pcall(function()
return TeleportService:GetPlayerPlaceInstanceAsync(followId)
end)
-- followId è l'ID utente del giocatore per il quale si desidera recuperare il luogo e l'ID del lavoro
if success then
-- Teletrasporta il giocatore al successo in base a jobId
TeleportService:TeleportToPlaceInstance(placeId, jobIdOrErr, player)
else
-- Invia un avviso in base all'errore restituito
warn(jobIdOrErr)
end
else
warn(("Il giocatore %d non sta seguendo un altro giocatore!"):format(player.UserId))
end
end)GetTeleportSetting
PromptExperienceDetailsAsync
TeleportService:PromptExperienceDetailsAsync(
Restituzioni
Campioni di codice
Mostra i dettagli dell'esperienza al giocatore
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local success, result = pcall(function()
TeleportService:PromptExperienceDetailsAsync(player, 8357232245)
end)
if not success then
warn("Errore nel richiedere i dettagli dell'esperienza: " .. tostring(result))
end
if result == Enum.PromptExperienceDetailsResult.PromptClosed then
print("Il giocatore ha chiuso la richiesta dei dettagli dell'esperienza")
elseif result == Enum.PromptExperienceDetailsResult.TeleportAttempted then
print("Il giocatore ha scelto di teletrasportarsi all'esperienza")
endReserveServer
ReserveServerAsync
Parametri
Restituzioni
Campioni di codice
TeleportService: Teletrasferisci a un Server Riservato
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local code = TeleportService:ReserveServerAsync(game.PlaceId)
local players = Players:GetPlayers()
TeleportService:TeleportToPrivateServer(game.PlaceId, code, players)
-- Puoi aggiungere argomenti extra a questa funzione: spawnName, teleportData e customLoadingScreenTeleportService: Teletrasporta a un Server Riservato tramite Chat
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetGlobalDataStore()
-- Ottieni il codice salvato
local code = dataStore:GetAsync("ReservedServer")
if typeof(code) ~= "string" then -- Nessuno salvato, creane uno
code = TeleportService:ReserveServerAsync(game.PlaceId)
dataStore:SetAsync("ReservedServer", code)
end
local function joined(player)
player.Chatted:Connect(function(message)
if message == "riservato" 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")
-- imposta il gui di caricamento per questo luogo
loadingGui.Parent = playerGui
-- imposta il gui di caricamento per il luogo di destinazione
TeleportService:SetTeleportGui(loadingGui)
TeleportService:Teleport(PLACE_ID)SetTeleportSetting
Teleport
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")
-- imposta il gui di caricamento per questo luogo
loadingGui.Parent = playerGui
-- imposta il gui di caricamento per il luogo di destinazione
TeleportService:SetTeleportGui(loadingGui)
TeleportService:Teleport(PLACE_ID)Teletrasporto dal server
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local PLACE_ID = 0 -- sostituisci qui
local USER_ID = 1 -- sostituisci con l'UserId del giocatore
local player = Players:GetPlayerByUserId(USER_ID)
TeleportService:Teleport(PLACE_ID, player)TeleportAsync
TeleportPartyAsync
Restituzioni
Campioni di codice
Teletrasporta tutti i giocatori nel server
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local PLACE_ID = 0 -- sostituire
local playerList = Players:GetPlayers()
local success, result = pcall(function()
return TeleportService:TeleportPartyAsync(PLACE_ID, playerList)
end)
if success then
local jobId = result
print("Giocatori teletrasportati a", jobId)
else
warn(result)
endTeleportToPlaceInstance
Restituzioni
()
Campioni di codice
Seguire un altro giocatore
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local followId = player.FollowUserId
if followId and followId ~= 0 then
-- Questo giocatore sta seguendo qualcun altro? In tal caso, scopri dove si trova
local success, currentInstance, error, placeId, jobIdOrErr = pcall(function()
return TeleportService:GetPlayerPlaceInstanceAsync(followId)
end)
-- followId è l'ID utente del giocatore per il quale si desidera recuperare il luogo e l'ID del lavoro
if success then
-- Teletrasporta il giocatore al successo in base a jobId
TeleportService:TeleportToPlaceInstance(placeId, jobIdOrErr, player)
else
-- Invia un avviso in base all'errore restituito
warn(jobIdOrErr)
end
else
warn(("Il giocatore %d non sta seguendo un altro giocatore!"):format(player.UserId))
end
end)TeleportToPrivateServer
Restituzioni
()
Campioni di codice
TeleportService: Teletrasporta a un Server Riservato tramite Chat
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetGlobalDataStore()
-- Ottieni il codice salvato
local code = dataStore:GetAsync("ReservedServer")
if typeof(code) ~= "string" then -- Nessuno salvato, creane uno
code = TeleportService:ReserveServerAsync(game.PlaceId)
dataStore:SetAsync("ReservedServer", code)
end
local function joined(player)
player.Chatted:Connect(function(message)
if message == "riservato" then
TeleportService:TeleportToPrivateServer(game.PlaceId, code, { player })
end
end)
end
Players.PlayerAdded:Connect(joined)TeleportService: Teletrasferisci a un Server Riservato
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local code = TeleportService:ReserveServerAsync(game.PlaceId)
local players = Players:GetPlayers()
TeleportService:TeleportToPrivateServer(game.PlaceId, code, players)
-- Puoi aggiungere argomenti extra a questa funzione: spawnName, teleportData e customLoadingScreenTeleportToSpawnByName
Restituzioni
()
Campioni di codice
TeleportService:TeleportToSpawnByName
local TeleportService = game:GetService("TeleportService")
TeleportService:TeleportToSpawnByName(1818, "TeleportSpawn")Eventi
LocalPlayerArrivedFromTeleport
TeleportService.LocalPlayerArrivedFromTeleport(
Parametri
dataTable:Variant |
TeleportInitFailed
TeleportService.TeleportInitFailed(
player:Instance, teleportResult:Enum.TeleportResult, errorMessage:string, placeId:number, teleportOptions:Instance
Parametri