Shop GUI not acting as expected

I’m trying to make a shop GUI for a simulator I’m making, except it keeps opening up every time I spawn.
robloxapp-20210626-1911300.wmv (3.0 MB)

Is there any way to make the main frame of the GUI to only open when intended to, or in this case, only when the “Shop” button is clicked?

Image Button:

local opened = false
script.Parent.MouseButton1Click:Connect(function()
     if opened then
          script.Parent.Visible = false
          opened = false
     else
          script.Parent.Visible = true
          opened = true
end)

Disclaimer: I didn’t test it so it may have an error in it I didn’t see. But you get the idea.

Where exactly was I supposed to insert the script?

I assume you have a button and a frame where the shop is. Put this script under the button but change the script.Parent part in the if and else statement to the location of the frame.

Is the Frame/Gui Enbaled? or Visible?

Here’s my setup:
setup

script.Parent.Parent.Frame.Visible = false
local opened = false

script.Parent.MouseButton1Click:Connect(function()
     if opened then
          script.Parent.Parent.Frame.Visible = false
          opened = false
     else
          script.Parent.Parent.Frame.Visible = true
          opened = true
end)

This should work.

EDIT: OK now this should work lol.

Make the frame visible = false if its true

The frame is somehow enabled already when you spawn in the game. It should only be visible when it is called or clicked to open.

My code should work, test it with that.

3 Likes

Yeah also, I noticed you keep missing the second end after the if conditional LoL.

Just add it in when you paste it in, I wrote it in the replies heh so I didn’t have it auto fill. Let me know if it works and fixes the issue.

Make a LocalScript Inside your openshop
You can name it to whatever you want inside the local script copy and paste this:

local frame = script.Parent.Parent.Frame
local button = script.Parent

frame.Visible = false
button.MouseButton1Click:Connect(function()
frame.Visible = not frame.Visible
end)

It should work!