My script for opening a frame works but when i press 2nd time it doesn't close the frame

here is the script:

1. script.Parent.MouseButton1Click:Connect(function()
2. 	script.Parent.Parent.Background.Visible = true
2. end)
3. script.Parent.MouseButton1Click:Connect(function()
4. 	script.Parent.Parent.Background.Visible = false
5. end)
1 Like

you gotta give more context, is background the frames name?
what is the frame named?
how does the explorer look?

1 Like

yep, the frame is called “Background”

local button = script.Parent
local frame = button.Parent.Background

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

OR

local button = script.Parent
local frame = button.Parent.Background

button.MouseButton1Click:Connect(function()
 if frame.Visible then
   frame.Visible = false
 else
  frame.Visible = true
 end
end)

the reason why this doesn’t work is because you NEVER check for if the frame is visible, you just run the two functions

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.