TeleportService
Mostrar obsoleto
Resumo
Métodos
- TeleportToPrivateServer(placeId : number,reservedServerAccessCode : string,players : Instances,spawnName : string,teleportData : Variant,customLoadingScreen : Instance):()
- TeleportToSpawnByName(placeId : number,spawnName : string,player : Instance,teleportData : Variant,customLoadingScreen : Instance):()
- TeleportPartyAsync(placeId : number,players : Instances,teleportData : Variant,customLoadingScreen : Instance):string
Eventos
- TeleportInitFailed(player : Instance,teleportResult : Enum.TeleportResult,errorMessage : string,placeId : number,teleportOptions : Instance):RBXScriptSignal
Propriedades
Métodos
GetArrivingTeleportGui
Devolução
Amostras de código
Lidando com uma GUI de carregamento de teletransporte
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
Devolução
Variant
Amostras de código
Getting LocalPlayer Teleport Data
local TeleportService = game:GetService("TeleportService")
local teleportData = TeleportService:GetLocalPlayerTeleportData()
print("Local player arrived with this data:", teleportData)
SetTeleportGui
()
Parâmetros
Valor Padrão: ""
Devolução
()
Amostras de código
Teletransportando o jogador local
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 -- substitua aqui
local loadingGui = ReplicatedStorage:FindFirstChild("LoadingGui")
-- pai da gui de carregamento para este lugar
loadingGui.Parent = playerGui
-- defina a gui de carregamento para o local de destino
TeleportService:SetTeleportGui(loadingGui)
TeleportService:Teleport(PLACE_ID)
SetTeleportSetting
()
Parâmetros
Valor Padrão: ""
value: Variant
Valor Padrão: ""
Devolução
()
Teleport
()
Parâmetros
Valor Padrão: ""
Valor Padrão: "nil"
teleportData: Variant
Valor Padrão: ""
Valor Padrão: "nil"
Devolução
()
Amostras de código
Teletransportando o jogador local
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 -- substitua aqui
local loadingGui = ReplicatedStorage:FindFirstChild("LoadingGui")
-- pai da gui de carregamento para este lugar
loadingGui.Parent = playerGui
-- defina a gui de carregamento para o local de destino
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)
TeleportToPlaceInstance
()
Parâmetros
Valor Padrão: ""
Valor Padrão: ""
Valor Padrão: "nil"
Valor Padrão: ""
teleportData: Variant
Valor Padrão: ""
Valor Padrão: "nil"
Devolução
()
Amostras de código
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
()
Parâmetros
Valor Padrão: ""
Valor Padrão: ""
players: Instances
Valor Padrão: ""
Valor Padrão: ""
teleportData: Variant
Valor Padrão: ""
Valor Padrão: "nil"
Devolução
()
Amostras de código
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
()
Parâmetros
Valor Padrão: ""
Valor Padrão: ""
Valor Padrão: "nil"
teleportData: Variant
Valor Padrão: ""
Valor Padrão: "nil"
Devolução
()
Amostras de código
Serviço de Teletransporte: TeleportToSpawnByName
local TeleportService = game:GetService("TeleportService")
TeleportService:TeleportToSpawnByName(1818, "TeleportSpawn")
GetPlayerPlaceInstanceAsync
Parâmetros
Valor Padrão: ""
Devolução
Amostras de código
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)
ReserveServer
Parâmetros
Valor Padrão: ""
Devolução
Amostras de código
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)
TeleportAsync
Parâmetros
Valor Padrão: ""
players: Instances
Valor Padrão: ""
Valor Padrão: "nil"
Devolução
TeleportPartyAsync
Parâmetros
Valor Padrão: ""
players: Instances
Valor Padrão: ""
teleportData: Variant
Valor Padrão: ""
Valor Padrão: "nil"
Devolução
Amostras de código
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