如何使用TeleportPartyAsync()在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

任何帮助将不胜感激!

点赞
用户2858170
用户2858170

这不会显示任何错误。

Lua 5.4 参考手册中得知:

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

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

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

将代码与Roblox的示例进行比较:

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
2021-06-02 07:37:40