【问题标题】:TransferToGame with UIButton - How? (Lua)使用 UIButton 的 TransferToGame - 如何? (卢阿)
【发布时间】:2021-06-18 15:33:31
【问题描述】:

我目前正在为我的游戏制作主菜单,其中一个按钮(“部署”按钮)需要将玩家转移到地图。但是,我无法让“部署”按钮工作。

local button = script.parent
local gameteleport = script:GetCustomProperty("Game")
local Deploy = script:GetCustomProperty("Deploy"):WaitForObject()


Deploy.isEnabled = true   --EnableUI
UI.SetCursorVisible(true)
UI.CanCursorInteractWithUI(true)

function OnClicked(whichButton)
    print("button clicked: " .. whichButton.name)
    player:TransferToGame("703a40/map-the-cauldron")
end

function OnHovered(whichButton)
    --print("button hovered: " .. whichButton.name)
end

function OnUnhovered(whichButton)
    --print("button unhovered: " .. whichButton.name)
end

button.clickedEvent:Connect(OnClicked)
button.hoveredEvent:Connect(OnHovered)
button.unhoveredEvent:Connect(OnUnhovered)

【问题讨论】:

    标签: user-interface lua coregames


    【解决方案1】:

    您遇到的唯一问题是您从中调用“TransferToGame”函数的网络上下文。 “TransferToGame”函数需要从服务器端脚本调用,而不是从客户端脚本调用。您可以通过使用从客户端广播到服务器的事件来通知服务器要传输哪个播放器来做到这一点。

    客户端脚本:

    local button = script.parent
    local gameteleport = script:GetCustomProperty("Game")
    local Deploy = script:GetCustomProperty("Deploy"):WaitForObject()
    
    
    Deploy.isEnabled = true   --EnableUI
    UI.SetCursorVisible(true)
    UI.CanCursorInteractWithUI(true)
    
    function OnClicked(whichButton)
        print("button clicked: " .. whichButton.name)
        --Tell the server to transfer the player
        Events.BroadcastToServer("Transfer Player")
    end
    
    function OnHovered(whichButton)
        --print("button hovered: " .. whichButton.name)
    end
    
    function OnUnhovered(whichButton)
        --print("button unhovered: " .. whichButton.name)
    end
    
    button.clickedEvent:Connect(OnClicked)
    button.hoveredEvent:Connect(OnHovered)
    button.unhoveredEvent:Connect(OnUnhovered)
    

    服务器端脚本:

    --This function is called when the "Transfer Player" message is received
    function OnTransfer(player)
        --transfer the player
        player:TransferToGame("703a40/map-the-cauldron")
    end
    --Connect the "OnTransfer" function to the "Transfer Player" event
    Events.ConnectForPlayer("Transfer Player", OnTransfer)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-05
      • 2014-08-17
      • 1970-01-01
      • 1970-01-01
      • 2020-04-18
      • 1970-01-01
      • 2012-04-07
      相关资源
      最近更新 更多