概要
方法
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):() |
活动
LocalPlayerArrivedFromTeleport(loadingGui: Instance,dataTable: Variant):RBXScriptSignal |
TeleportInitFailed(player: Instance,teleportResult: Enum.TeleportResult,errorMessage: string,placeId: number,teleportOptions: Instance):RBXScriptSignal |
API 参考
属性
CustomizedTeleportUI
方法
GetArrivingTeleportGui
返回
代码示例
处理传送加载GUI
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
返回
Variant
代码示例
获取 LocalPlayer 传送数据
local TeleportService = game:GetService("TeleportService")
local teleportData = TeleportService:GetLocalPlayerTeleportData()
print("本地玩家使用以下数据到达:", teleportData)GetPlayerPlaceInstanceAsync
参数
返回
代码示例
跟随其他玩家
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
-- 这个玩家在跟随其他人吗?如果是,找出他们在哪里
local success, currentInstance, error, placeId, jobIdOrErr = pcall(function()
return TeleportService:GetPlayerPlaceInstanceAsync(followId)
end)
-- followId 是您想要检索位置和作业 ID 的玩家的用户 ID
if success then
-- 根据 jobId 在成功时传送玩家
TeleportService:TeleportToPlaceInstance(placeId, jobIdOrErr, player)
else
-- 根据返回的错误发布警告
warn(jobIdOrErr)
end
else
warn(("玩家 %d 没有跟随其他玩家!"):format(player.UserId))
end
end)GetTeleportSetting
PromptExperienceDetailsAsync
TeleportService:PromptExperienceDetailsAsync(
代码示例
向玩家显示体验详情
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("提示体验详情时出现错误: " .. tostring(result))
end
if result == Enum.PromptExperienceDetailsResult.PromptClosed then
print("玩家关闭了体验详情提示")
elseif result == Enum.PromptExperienceDetailsResult.TeleportAttempted then
print("玩家选择传送到体验")
endReserveServer
ReserveServerAsync
参数
返回
代码示例
传送服务:传送到保留服务器
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)
-- 您可以向此函数添加额外的参数:spawnName,teleportData和customLoadingScreenTeleportService:通过聊天传送到预留服务器
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetGlobalDataStore()
-- 获取保存的代码
local code = dataStore:GetAsync("ReservedServer")
if typeof(code) ~= "string" then -- 没有保存,创建一个
code = TeleportService:ReserveServerAsync(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
参数
返回
()
代码示例
传送本地玩家
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 -- 在此处替换
local loadingGui = ReplicatedStorage:FindFirstChild("LoadingGui")
-- 将加载 GUI 设置为此地点的父级
loadingGui.Parent = playerGui
-- 设置目标地点的加载 GUI
TeleportService:SetTeleportGui(loadingGui)
TeleportService:Teleport(PLACE_ID)SetTeleportSetting
Teleport
返回
()
代码示例
传送本地玩家
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 -- 在此处替换
local loadingGui = ReplicatedStorage:FindFirstChild("LoadingGui")
-- 将加载 GUI 设置为此地点的父级
loadingGui.Parent = playerGui
-- 设置目标地点的加载 GUI
TeleportService:SetTeleportGui(loadingGui)
TeleportService:Teleport(PLACE_ID)从服务器传送
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local PLACE_ID = 0 -- 在这里替换
local USER_ID = 1 -- 用玩家的 UserId 替换
local player = Players:GetPlayerByUserId(USER_ID)
TeleportService:Teleport(PLACE_ID, player)TeleportAsync
TeleportPartyAsync
返回
代码示例
传送服务器中的所有玩家
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local PLACE_ID = 0 -- 替换
local playerList = Players:GetPlayers()
local success, result = pcall(function()
return TeleportService:TeleportPartyAsync(PLACE_ID, playerList)
end)
if success then
local jobId = result
print("玩家已传送到", jobId)
else
warn(result)
endTeleportToPlaceInstance
返回
()
代码示例
跟随其他玩家
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
-- 这个玩家在跟随其他人吗?如果是,找出他们在哪里
local success, currentInstance, error, placeId, jobIdOrErr = pcall(function()
return TeleportService:GetPlayerPlaceInstanceAsync(followId)
end)
-- followId 是您想要检索位置和作业 ID 的玩家的用户 ID
if success then
-- 根据 jobId 在成功时传送玩家
TeleportService:TeleportToPlaceInstance(placeId, jobIdOrErr, player)
else
-- 根据返回的错误发布警告
warn(jobIdOrErr)
end
else
warn(("玩家 %d 没有跟随其他玩家!"):format(player.UserId))
end
end)TeleportToPrivateServer
返回
()
代码示例
TeleportService:通过聊天传送到预留服务器
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetGlobalDataStore()
-- 获取保存的代码
local code = dataStore:GetAsync("ReservedServer")
if typeof(code) ~= "string" then -- 没有保存,创建一个
code = TeleportService:ReserveServerAsync(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)传送服务:传送到保留服务器
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)
-- 您可以向此函数添加额外的参数:spawnName,teleportData和customLoadingScreenTeleportToSpawnByName
返回
()
代码示例
传送服务:按名称传送到生成点
local TeleportService = game:GetService("TeleportService")
-- 将玩家传送到指定的生成点
TeleportService:TeleportToSpawnByName(1818, "TeleportSpawn")活动
LocalPlayerArrivedFromTeleport
TeleportService.LocalPlayerArrivedFromTeleport(
参数
dataTable:Variant |
TeleportInitFailed
TeleportService.TeleportInitFailed(
player:Instance, teleportResult:Enum.TeleportResult, errorMessage:string, placeId:number, teleportOptions:Instance
参数