GUI open script not working

For my shop GUI, my script below is not working to make it close/open.

script.Parent.MouseButton1Down:Connect(function()
script.Parent.Parent.Visible=false

script.Parent.MouseButton1Down:Connect(function()
script.Parent.Parent.Visible=true

Can anyone help?

Please debug your own code before posting threads. Read the console (F9 or Studio console) to see where your code is erroring and do a bit of research on how to use things like functions.

You never close your functions after opening them and you have a MouseButton1Down connection that both sets the Gui’s visibility to true and again to false, which just cancels out the visibility altogether. You can fix this by using one connection, closing it and negating the Gui’s visibility.

local frame = script.Parent.Parent

script.Parent.MouseButton1Down:Connect(function ()
    frame.Visible = not frame.Visible
end)

Be sure to use variables as well so you can prevent code redundancy and at some point, please don’t nest LocalScripts deep inside your hierarchy, just makes it worse on trying to access other parts of the Gui and finding it when you want to update code. LocalScripts are best placed under the Gui itself.

2 Likes

As said above, please debug your code before posting threads.

You can use the console, the output, code breakers and prints.