【问题标题】:Roblox Gui Toggles On/Off only on the First clickRoblox Gui 仅在第一次单击时打开/关闭
【发布时间】:2020-05-16 15:13:24
【问题描述】:

触摸 NPC 时我的 gui 会打开。它显示一个“关闭”按钮。当第一次单击关闭按钮时,它通过设置 frame.Visible = false 和 gui.Enabled = false 来关闭 gui。

当我再次触摸 NPC 时,gui 会按原样显示。虽然按钮不会导致属性设置为 false。我已经输出了 frame.Visible 的值并打印了“False”,但在“属性”窗口中,该值显示为“True”。

这是怎么回事?

--NPC Script
local soldier = game.Workspace["Level6"].Soldier.Humanoid.RootPart
local player = game.Players.LocalPlayer

local function onTouch(touchPart)
    if touchPart.Parent:FindFirstChild("Humanoid") then
        local gui = game.Players.LocalPlayer.PlayerGui.EndScreenGui
        local frame = gui.Frame

        frame.Visible = true
        gui.Enabled = true
        print("On")
    end
end

soldier.Touched:Connect(onTouch)

这是我的 gui 代码:

local button = script.Parent

function onClicked()
    local frame = button.Parent
    local gui = frame.Parent

    --frame.Visible = false
    gui.Enabled = false
    print(frame.Visible)
end

button.MouseButton1Click:Connect(onClicked)

【问题讨论】:

    标签: user-interface toggle roblox


    【解决方案1】:

    如果我们进行语法高亮显示,我们可以看到:

    function onClicked()
        local frame = button.Parent
        local gui = frame.Parent
    
        --frame.Visible = false
        gui.Enabled = false
        print(frame.Visible)
    end
    

    frame.Visible 行已被注释掉,因此它不会运行。删除该行之前的--,您的脚本应该一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-04
      • 1970-01-01
      • 1970-01-01
      • 2016-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多