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.
I’ve attempted this on my own to no avail. Help?
P.S. Sorry for the messy script.
lV0rd
(Tin)
September 23, 2022, 8:09pm
#2
Use if statments and a variable and change the variable when openning and closing.
Kaid3n22
(Kaiden)
September 23, 2022, 8:09pm
#3
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.
Kaid3n22
(Kaiden)
September 23, 2022, 8:13pm
#6
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.
Andrew10635
(Andrew 10635)
September 23, 2022, 8:16pm
#8
You have 4 .Parents
The script has 3 parents excluding playergui
4th goes to playergui
remove .Parent 4
Kaid3n22
(Kaiden)
September 23, 2022, 8:17pm
#9
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.
Kaid3n22
(Kaiden)
September 23, 2022, 8:18pm
#11
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.
Kaid3n22
(Kaiden)
September 23, 2022, 8:20pm
#13
Did you check the output?
These should have been printed.
This is what the output says.
The error links to the line of code that contains the variable defining “menu”.
Kaid3n22
(Kaiden)
September 23, 2022, 8:23pm
#15
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.
Kaid3n22
(Kaiden)
September 23, 2022, 8:26pm
#17
Yes, I mean the ScreenGui named Menu. I’m assuming there is another script that deletes the Menu inside of the player
1 Like
Pegagittt
(Pegagit)
September 23, 2022, 8:28pm
#18
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.
Pegagittt
(Pegagit)
September 23, 2022, 8:31pm
#20
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