Klasa silnika
TeleportService
*Ta zawartość została przetłumaczona przy użyciu narzędzi AI (w wersji beta) i może zawierać błędy. Aby wyświetlić tę stronę w języku angielskim, kliknij tutaj.
Podsumowanie
Właściwości
Metody
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):() |
Zdarzenia
LocalPlayerArrivedFromTeleport(loadingGui: Instance,dataTable: Variant):RBXScriptSignal |
TeleportInitFailed(player: Instance,teleportResult: Enum.TeleportResult,errorMessage: string,placeId: number,teleportOptions: Instance):RBXScriptSignal |
Materiały referencyjne dotyczące interfejsów API
Właściwości
CustomizedTeleportUI
Metody
GetArrivingTeleportGui
Zwroty
Przykłady kodu
Obsługa GUI ładowania teleportu
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
Zwroty
Variant
Przykłady kodu
Odbieranie danych teleportacji LocalPlayer
local TeleportService = game:GetService("TeleportService")
local teleportData = TeleportService:GetLocalPlayerTeleportData()
print("Lokalny gracz przybył z tymi danymi:", teleportData)GetPlayerPlaceInstanceAsync
Parametry
Zwroty
Przykłady kodu
Śledzenie innego gracza
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
-- Czy ten gracz śledzi kogokolwiek? Jeśli tak, znajdź, gdzie są
local success, currentInstance, error, placeId, jobIdOrErr = pcall(function()
return TeleportService:GetPlayerPlaceInstanceAsync(followId)
end)
-- followId to identyfikator użytkownika gracza, dla którego chcesz uzyskać identyfikator miejsca i identyfikator zadania
if success then
-- Teleportuje gracza po powodzeniu na podstawie jobId
TeleportService:TeleportToPlaceInstance(placeId, jobIdOrErr, player)
else
-- Wyświetla ostrzeżenie na podstawie zwróconego błędu
warn(jobIdOrErr)
end
else
warn(("Gracz %d nie śledzi innego gracza!"):format(player.UserId))
end
end)GetTeleportSetting
PromptExperienceDetailsAsync
TeleportService:PromptExperienceDetailsAsync(
Przykłady kodu
Pokaż szczegóły doświadczenia graczowi
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("Błąd podczas wywoływania szczegółów doświadczenia: " .. tostring(result))
end
if result == Enum.PromptExperienceDetailsResult.PromptClosed then
print("Gracz zamknął okno szczegółów doświadczenia")
elseif result == Enum.PromptExperienceDetailsResult.TeleportAttempted then
print("Gracz wybrał teleportację do doświadczenia")
endReserveServer
ReserveServerAsync
Parametry
Zwroty
Przykłady kodu
TeleportService: Teleportuj do zarezerwowanego serwera
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)
-- Możesz dodać dodatkowe argumenty do tej funkcji: spawnName, teleportData i customLoadingScreenTeleportService: Teleportuj do zarezerwowanego serwera za pomocą czatu
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetGlobalDataStore()
-- Pobierz zapisany kod
local code = dataStore:GetAsync("ReservedServer")
if typeof(code) ~= "string" then -- Nic nie zapisano, utwórz nowy
code = TeleportService:ReserveServerAsync(game.PlaceId)
dataStore:SetAsync("ReservedServer", code)
end
local function joined(player)
player.Chatted:Connect(function(message)
if message == "zarezerwowany" then
TeleportService:TeleportToPrivateServer(game.PlaceId, code, { player })
end
end)
end
Players.PlayerAdded:Connect(joined)SetTeleportGui
Parametry
Zwroty
()
Przykłady kodu
Teleportowanie lokalnego gracza
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 -- zastąp tutaj
local loadingGui = ReplicatedStorage:FindFirstChild("LoadingGui")
-- dodaj interfejs ładowania dla tego miejsca
loadingGui.Parent = playerGui
-- ustaw interfejs ładowania dla docelowego miejsca
TeleportService:SetTeleportGui(loadingGui)
TeleportService:Teleport(PLACE_ID)SetTeleportSetting
Teleport
Zwroty
()
Przykłady kodu
Teleportowanie lokalnego gracza
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 -- zastąp tutaj
local loadingGui = ReplicatedStorage:FindFirstChild("LoadingGui")
-- dodaj interfejs ładowania dla tego miejsca
loadingGui.Parent = playerGui
-- ustaw interfejs ładowania dla docelowego miejsca
TeleportService:SetTeleportGui(loadingGui)
TeleportService:Teleport(PLACE_ID)Teleportacja z serwera
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local PLACE_ID = 0 -- zamień tutaj
local USER_ID = 1 -- zamień na Id Użytkownika gracza
local player = Players:GetPlayerByUserId(USER_ID)
TeleportService:Teleport(PLACE_ID, player)TeleportAsync
TeleportPartyAsync
Zwroty
Przykłady kodu
Teleportuj wszystkich graczy na serwerze
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local PLACE_ID = 0 -- zmień
local playerList = Players:GetPlayers()
local success, result = pcall(function()
return TeleportService:TeleportPartyAsync(PLACE_ID, playerList)
end)
if success then
local jobId = result
print("Gracze zostali teleportowani do", jobId)
else
warn(result)
endTeleportToPlaceInstance
Zwroty
()
Przykłady kodu
Śledzenie innego gracza
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
-- Czy ten gracz śledzi kogokolwiek? Jeśli tak, znajdź, gdzie są
local success, currentInstance, error, placeId, jobIdOrErr = pcall(function()
return TeleportService:GetPlayerPlaceInstanceAsync(followId)
end)
-- followId to identyfikator użytkownika gracza, dla którego chcesz uzyskać identyfikator miejsca i identyfikator zadania
if success then
-- Teleportuje gracza po powodzeniu na podstawie jobId
TeleportService:TeleportToPlaceInstance(placeId, jobIdOrErr, player)
else
-- Wyświetla ostrzeżenie na podstawie zwróconego błędu
warn(jobIdOrErr)
end
else
warn(("Gracz %d nie śledzi innego gracza!"):format(player.UserId))
end
end)TeleportToPrivateServer
Zwroty
()
Przykłady kodu
TeleportService: Teleportuj do zarezerwowanego serwera za pomocą czatu
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetGlobalDataStore()
-- Pobierz zapisany kod
local code = dataStore:GetAsync("ReservedServer")
if typeof(code) ~= "string" then -- Nic nie zapisano, utwórz nowy
code = TeleportService:ReserveServerAsync(game.PlaceId)
dataStore:SetAsync("ReservedServer", code)
end
local function joined(player)
player.Chatted:Connect(function(message)
if message == "zarezerwowany" then
TeleportService:TeleportToPrivateServer(game.PlaceId, code, { player })
end
end)
end
Players.PlayerAdded:Connect(joined)TeleportService: Teleportuj do zarezerwowanego serwera
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)
-- Możesz dodać dodatkowe argumenty do tej funkcji: spawnName, teleportData i customLoadingScreenTeleportToSpawnByName
Zwroty
()
Przykłady kodu
TeleportService:TeleportToSpawnByName
local TeleportService = game:GetService("TeleportService")
-- Teleportacje gracza do spawn'a o nazwie "TeleportSpawn"
TeleportService:TeleportToSpawnByName(1818, "TeleportSpawn")Zdarzenia
LocalPlayerArrivedFromTeleport
TeleportService.LocalPlayerArrivedFromTeleport(
Parametry
dataTable:Variant |
TeleportInitFailed
TeleportService.TeleportInitFailed(
player:Instance, teleportResult:Enum.TeleportResult, errorMessage:string, placeId:number, teleportOptions:Instance
Parametry