Hey guys! I’m working on a simple script that I should be able to write but for whatever reason can’t. The purpose is to, if a GUI is visible, to hide the GUI, and if the GUI is hidden, then to show the GUI. So basically it changes the visibility to the opposite.
My script is here, it doesn’t error.
local vis = script.Parent.Parent.ShopFrame.Visible
script.Parent.MouseButton1Down:Connect(function()
if vis==false then
script.Parent.Parent.ShopFrame.Visible=true
else if vis==true then
script.Parent.Parent.ShopFrame.Visible=false
end
end
end)
It’s really simple, but what am I doing wrong. (This is a LocalScript in button GUI btw)
That’s not the problem, what you’re doing is adding an infinite yield because you’re saying whenever the GUI= visible then make it false but if it isn’t visible make it visible and it’s just repeating that infinitely
That isn’t the problem, the problem is that they’re assigning a static value (whatever Boolean is assigned to the GuiObject’s ‘Visible’ property) to a variable named “vis”, this variable is not a reference to the GuiObject’s ‘Visible’ property but instead a reference to its initial ‘Visible’ property’s value. The solution is fairly trivial, they just need to make the variable point/refer to the GuiObject itself, that way it can be used to fetch the current state of the GuiObject’s ‘Visible’ property whenever necessary.
local Script = script
local GuiObject = Script.Parent
print(GuiObject.Visible) --false
GuiObject.Visible = true
print(GuiObject.Visible) --true
local frame = script.Parent.Parent.ShopFrame
script.Parent.MouseButton1Down:Connect(function()
if frame.Visible == false then
frame.Visible = true
else if frame.Visible == true then
frame.Visible = false
end
end)