How can I make a menu open and close button

In this image, I have created a menu open button. But once it opens, I want the same menu open button to be able to close the menu.

Here’s the scope of my Explorer.
image

I’ve attempted this on my own to no avail. Help?

P.S. Sorry for the messy script.

Use if statments and a variable and change the variable when openning and closing.

Well, you have it partially correct, but don’t alternate it.

local menu = script.Parent.Parent.Parent.Parent.Menu

script.Parent.MouseButton1Click:Connect(function()
    menu.Enabled = not menu.Enabled
end)

this simply alternates the Enabled without any further statements (probably the easiest way)

2 Likes

Just realized I made a typo that wasn’t supposed to be in the screenshot. I will fix asap.

That looks logically sound, but this error shows up.

Looks like scope may be messed up.

It seems that it is selecting the PlayerGui and not the menu. I did the exact same variable setting as you did, so there should be no problem…?

Yeah, I see the script. The error doesn’t make any sense.

I’m think it has something to do with the local aspect of the script.

You have 4 .Parents
The script has 3 parents excluding playergui
4th goes to playergui
remove .Parent 4

You need to get to the PlayerGui to get to the menu.

That’s not correct, it links to the open button’s gui in that case.

The script being local doesn’t matter, but I guess we should try printing things?

local menu = script.Parent.Parent.Parent.Parent.Menu
print(menu.Parent, menu, menu:GetChildren())

script.Parent.MouseButton1Click:Connect(function()
    menu.Enabled = not menu.Enabled
end)

The same error applies. Not sure whats happening. The error is preventing the printing lines of code from running.

Did you check the output?

These should have been printed.

This is what the output says.
image

The error links to the line of code that contains the variable defining “menu”.

Are you sure the Menu is archivable?

Archivable is set to true. When you ask if the menu is archivable you do mean the screen GUI named Menu that contains the menu popup right?

edit: if yes, that is the one is listed as archivable.

Yes, I mean the ScreenGui named Menu. I’m assuming there is another script that deletes the Menu inside of the player

1 Like
script.Parent.MouseButton1Click:Connect(function()

if script.Parent.Parent.Parent.Parent.Menu.Enabled == false then

script.Parent.Parent.Parent.Parent.Menu.Enabled = true

else

script.Parent.Parent.Parent.Parent.Menu.Enabled = false

end

end)

The part that confuses me is that both “script.Parent.Parent.Parent.Parent.Menu” and the variable version “local menu = script.Parent.Parent.Parent.Parent.Menu” mean the exact same thing, as they quite literally lead to the same object in the explorer.

Yeah its the same thing but local menu saves the data what is inside so if you say menu its like script.Parent.Parent.Parent.Parent.Menu