【发布时间】:2020-10-14 05:52:41
【问题描述】:
将 UI_ELEMENT.Visible 更改为 true,然后 false 显示和隐藏 UI 元素,但是当我再次将其切换为 true 时,它不会重新出现。我相信这可能是我如何做而不是我在做什么的问题。
嗨, 我是 Roblox Lua 的新手(但我有 Javascript 和 C# 经验)。我正在制作“车库”或“零件”GUI。我正在尝试在文本对象上制作点击检测器,将 UI 元素的 UI_ELEMENT.Visible 设置为 true。并且一个文本按钮(前面提到的 UI 元素的一部分)将 UI_ELEMENT.Visible 设置回 false。
这个过程运行良好,直到我多次运行它(例如设置为 true,然后设置为 false,然后再次设置为 true)。 UI_ELEMENT.Visible 被“锁定”为 true(因为将其设置为 false 只会导致下一帧将其设置回 true),但 UI 不显示。
代码:
click_detector1.MouseClick:connect(function(player) -- When clicked
_G.PlayerInfo[player.Name].status = "In Garage" -- set player status to in garage (works fine no issues)
_G.PlayerInfo[player.Name].topbar = "" -- reset topbar (works)
print("this is only supposed to happen once") -- a check to see if this is running more than once
game.Players[tostring(player.Name)].PlayerGui.Garage.menu.Visible = true -- one way that should work
--.Enabled = true -- another way that should work
--.menu.Position = UDim2.new(0.5, 0, 0,0) -- another way that should work (setting position to center of screen)
end)
上面是一个服务器脚本(我们称之为脚本#1)。
button = script.Parent
local function onButtonActivated()
local Players = game:GetService("Players")
local player = Players.LocalPlayer -- get the local player
print("I am only running once") -- test to see if this is running more than once
game.Players[tostring(player.Name)].PlayerGui.Garage.menu.Visible = false -- one way that should work
--.Enabled = false -- another way that should work
--.menu.Position = UDim2.new(10, 0, 0,0) -- another way that should work (change x scale to off screen)
end
button.Activated:Connect(onButtonActivated)
以上是在本地脚本中(我们称之为脚本#2)。
有趣的是,我在“另一种应该起作用的方式”中提出的方法实际上都没有比循环的初始第一个周期更有效(例如,设置为 true,然后设置为 false,然后再次设置为 true)。
还记录测试以查看它们是否运行多次,每次循环通过时只运行一次(应该如此)。但是,这意味着将其设置为可见的代码也在运行,但没有记录错误或做它应该做的事情。
谢谢,丹尼尔·摩根
【问题讨论】:
-
如果我正确理解您的问题,您是在问为什么此代码在打开/关闭几次后开始失败?
-
@Kylaaa 是的,我不明白。
标签: user-interface lua roblox