我为播放器制作了一个设置 GUI,用于切断音乐或打开音乐,唯一的问题是 GUI 默认显示
我尝试移动代码或将 true 设置为 false...但没有任何效果,我将添加下面的代码
local open = true
script.Parent.MouseButton1Click:Connect(function()
if open == true then
open = false
script.Parent.Parent.Parent.MainFrame:TweenPosition(UDim2.new(0.278, 0,0.319, 0), "InOut", "Quad", 0.5, true)
else
open = true
script.Parent.Parent.Parent.MainFrame:TweenPosition(UDim2.new(0.278, 0,1, 0), "InOut", "Quad", 0.5, true)
end
end)
你如何向玩家展示 GUI?
这也意味着打开 .Visibile 属性的后续帧也将自动显示。
总而言之,这意味着 GUI 设置为首先显示其父级。
为了解决这个问题,您可能希望本地脚本也能控制 ScreenGui 和您想要显示的框架的适当属性。
例如
local mainFrame = script.Parent.Parent.Parent.MainFrame
local open = true
script.Parent.MouseButton1Click:Connect(function()
if open == true then
open = false
mainFrame:TweenPosition(UDim2.new(0.278, 0,0.319, 0), "InOut", "Quad", 0.5, true)
task.wait(0.5)
mainFrame.Visible = false
else
open = true
mainFrame.Visible = true
mainFrame:TweenPosition(UDim2.new(0.278, 0,1, 0), "InOut", "Quad", 0.5, true)
end
end)
当然,也可能是框架的起始位置设置不正确导致您当前遇到的问题。您必须在 GUI 编辑模式中设置它,或者在本地脚本的开头设置它:
...
mainFrame.Position = UDim2.new(0.278, 0,0.319, 0)
...
-- the rest of the code
...