Roblox Gui仅在第一次单击时切换开/关

问题描述 投票:0回答:1

我的GUI在触摸NPC时会打开。它显示一个“关闭”按钮。第一次单击关闭按钮时,它将通过设置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个回答
0
投票

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

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.