如何使用 ROBLOX 中的 TeleportPartyAsync() 传送到私人服务器?
How do you teleport to a private server using TeleportPartyAsync() in ROBLOX?
我想让它传送到私人服务器,但它不会传送,也没有显示任何错误。
代码如下:
local TeleportService = game:GetService("TeleportService")
local Players = {}
local GamePlayers = game:GetService("Players")
local IsTeleporting = false
local PlayersAllowed = script.Parent.Lobby.Teleporter.MaxPlayers
local function Teleport()
if #Players > 0 then
local TeleportPlayers = {}
for i = 1, #Players do
local I = i
if game.Players:FindFirstChild(Players[i]) then
table.insert(TeleportPlayers, GamePlayers:FindFirstChild(Players[i]))
TransitionEvent:FireClient(GamePlayers:FindFirstChild(Players[i]))
else
table.remove(Players, i)
end
end
wait(0.5)
IsTeleporting = true
pcall(function()
TeleportService:TeleportPartyAsync(TeleportID, TeleportPlayers)
end)
wait(0.5)
IsTeleporting = false
end
end
如有任何帮助,我们将不胜感激!
it doesn't show any errors.
pcall(function()
print("function called")
error("an error occurred!")
print("this will not be reached")
end)
这将打印 "function called"
。没有其他的。没有显示错误。
pcall (f [, arg1, ···])
Calls the function f with the given arguments in protected mode. This
means that any error inside f is not propagated; instead, pcall
catches the error and returns a status code. Its first result is the
status code (a boolean), which is true if the call succeeds without
errors. In such case, pcall also returns all results from the call,
after this first result. In case of any error, pcall returns false
plus the error object. Note that errors caught by pcall do not call a
message handler.
检查 pcall 的 return 值以查看函数 运行 是否成功。
将您的代码与 Roblox's example 进行比较:
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local placeId = 0 -- replace
local playerList = Players:GetPlayers()
local success, result = pcall(function()
return TeleportService:TeleportPartyAsync(placeId, playerList)
end)
if success then
local jobId = result
print("Players teleported to "..jobId)
else
warn(result)
end
我想让它传送到私人服务器,但它不会传送,也没有显示任何错误。
代码如下:
local TeleportService = game:GetService("TeleportService")
local Players = {}
local GamePlayers = game:GetService("Players")
local IsTeleporting = false
local PlayersAllowed = script.Parent.Lobby.Teleporter.MaxPlayers
local function Teleport()
if #Players > 0 then
local TeleportPlayers = {}
for i = 1, #Players do
local I = i
if game.Players:FindFirstChild(Players[i]) then
table.insert(TeleportPlayers, GamePlayers:FindFirstChild(Players[i]))
TransitionEvent:FireClient(GamePlayers:FindFirstChild(Players[i]))
else
table.remove(Players, i)
end
end
wait(0.5)
IsTeleporting = true
pcall(function()
TeleportService:TeleportPartyAsync(TeleportID, TeleportPlayers)
end)
wait(0.5)
IsTeleporting = false
end
end
如有任何帮助,我们将不胜感激!
it doesn't show any errors.
pcall(function()
print("function called")
error("an error occurred!")
print("this will not be reached")
end)
这将打印 "function called"
。没有其他的。没有显示错误。
pcall (f [, arg1, ···])
Calls the function f with the given arguments in protected mode. This means that any error inside f is not propagated; instead, pcall catches the error and returns a status code. Its first result is the status code (a boolean), which is true if the call succeeds without errors. In such case, pcall also returns all results from the call, after this first result. In case of any error, pcall returns false plus the error object. Note that errors caught by pcall do not call a message handler.
检查 pcall 的 return 值以查看函数 运行 是否成功。
将您的代码与 Roblox's example 进行比较:
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local placeId = 0 -- replace
local playerList = Players:GetPlayers()
local success, result = pcall(function()
return TeleportService:TeleportPartyAsync(placeId, playerList)
end)
if success then
local jobId = result
print("Players teleported to "..jobId)
else
warn(result)
end