【问题标题】:Roblox - Trying to get InvokeClient Remote Function WorkingRoblox - 试图让 InvokeClient 远程功能正常工作
【发布时间】:2016-06-18 23:10:20
【问题描述】:

在我的名为 MainGameScript 的服务器脚本中,我有这个代码块:

local myRemoteFunction = Instance.new("RemoteFunction")
myRemoteFunction.Parent = game.Workspace
myRemoteFunction.Name = "GetBuildInfo"

game.Players.PlayerAdded:connect(function(player)
    print("[MainGameScript] added player") 

    for i,v in pairs(Regions) do
        if (v.Value == 0) then
            Regions[i].Value = player.UserId
            break
        end
    end    

    local success, result = pcall(function() return myRemoteFunction:InvokeClient(player) end)
    if success then
       print(result)
    else
        print("Error calling RemoteFunction GetBuildInfo")
    end

结束)

我在 game.Workspace 中有一个名为 LocalBuildScript 的 LocalScript,其中包含:

function game.workspace.GetBuildInfo.OnClientInvoke()
    print("[GetBuildInfo] will send back local build info")
    return "this will be returned to the server caller script"
end

永远不会调用 GetBuildInfo 函数。我在调用函数中添加了一些调试打印行,并且该进程似乎在它使用 pcall 的时候死掉了......这几乎是 Roblox Wiki 中的远程函数客户端调用示例,不知道为什么它不工作并且我希望这里有人有使用 InvokeClient 脚本的经验。

谢谢, 安迪

【问题讨论】:

    标签: roblox


    【解决方案1】:

    它没有运行的原因是因为RemoteFunctions 引用的LocalScripts 预计会在其中某处的Player 实例内。我相当肯定是这种情况,因为我已经实现了一个类似的测试系统,但我将 LocalScript 保存在 Player 实例中。

    【讨论】:

    • 奇怪,我最初将它放在 PlayerScripts 中的 MainLocalScript 中,但它不起作用,但我从不同的脚本触发 InvokeClient,所以这可能是问题所在。您的解决方案有效,谢谢。
    • LocalScripts 仅在非常特定的位置运行。如果它们是玩家的后代,它们将运行,但它们也可以在 Tool 内部或 ReplicatedFirst 内部运行。完整列表可在 wiki 页面上找到:wiki.roblox.com/index.php?title=API:Class/LocalScript
    猜你喜欢
    • 2021-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 2010-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多