User interface Roblox Gui仅在第一次单击时切换开/关
触摸NPC时,我的gui打开。它显示一个“关闭”按钮。第一次单击关闭按钮时,它通过设置frame.Visible=false和gui.Enabled=false关闭gui 当我再次触摸NPC时,gui会显示,这是它应该显示的。尽管该按钮不会导致属性设置为false。我已经输出了frame.Visible的值,它打印“False”,尽管在属性窗口中,该值显示为“True” 这是怎么回事User interface Roblox Gui仅在第一次单击时切换开/关,user-interface,toggle,roblox,User Interface,Toggle,Roblox,触摸NPC时,我的gui打开。它显示一个“关闭”按钮。第一次单击关闭按钮时,它通过设置frame.Visible=false和gui.Enabled=false关闭gui 当我再次触摸NPC时,gui会显示,这是它应该显示的。尽管该按钮不会导致属性设置为false。我已经输出了frame.Visible的值,它打印“False”,尽管在属性窗口中,该值显示为“True” 这是怎么回事 --NPC Script local soldier = game.Workspace["Level6"].So
--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)
如果我们不使用照明,我们可以看到:
函数onClicked()
本地帧=按钮。父级
本地gui=frame.Parent
--frame.Visible=false
gui.Enabled=false
打印(帧可见)
结束
frame.Visible
行被注释掉,因此它不会运行。删除该行前面的--
,脚本应该都很好