エンジンクラス
TeleportService
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
概要
方法
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
-- ジョブIDに基づいて成功した場合にプレイヤーをテレポートします
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
パラメータ
戻り値
コードサンプル
TeleportService: 予約サーバーにテレポートする
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
-- ジョブIDに基づいて成功した場合にプレイヤーをテレポートします
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)TeleportService: 予約サーバーにテレポートする
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
戻り値
()
コードサンプル
TeleportService:TeleportToSpawnByName
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
パラメータ