【问题标题】:How do you teleport to a private server using TeleportPartyAsync() in ROBLOX?如何在 ROBLOX 中使用 TeleportPartyAsync() 传送到私人服务器?
【发布时间】:2021-08-20 06:42:10
【问题描述】:

我想让它传送到私人服务器,但它不会传送,也不会显示任何错误。

代码如下:

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

任何帮助将不胜感激!

【问题讨论】:

  • 你认为pcall 是做什么的?

标签: lua roblox


【解决方案1】:

它没有显示任何错误。

pcall(function()
   print("function called")
   error("an error occurred!")
   print("this will not be reached")
end)

这将打印"function called"。没有其他的。没有显示错误。

来自Lua 5.4 Reference Manual

pcall(f [, arg1, ···])

在保护模式下使用给定参数调用函数 f。这 表示 f 内的任何错误都不会传播;相反,pcall 捕获错误并返回状态码。它的第一个结果是 状态码(布尔值),如果调用成功,则为 true 错误。在这种情况下, pcall 还会返回调用的所有结果, 在这个第一个结果之后。如果出现任何错误,pcall 返回 false 加上错误对象。请注意,由 pcall 捕获的错误不会调用 消息处理程序。

检查 pcall 的返回值,看看函数是否运行成功。

将您的代码与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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-09
    • 2021-12-26
    • 2020-08-16
    • 2021-07-04
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 2017-05-05
    相关资源
    最近更新 更多