local button = script.Parent -- variable 1 (defines the button instead of using "script.Parent")
local menu = button.Parent -- variable 2 (defines the menu for your button instead of using "script.Parent.Parent and such")
button.MouseButton1Down:Connect(function() -- detects when the player clicks on the button (must use function for the code to properly work)
if menu.Enabled then -- checks if the menu is visible
menu.Enabled= false -- makes menu invisible
else
return -- if menu is already invisible, then it will return the function yielding it from working
end
end)
Using a ServerScript (Script) will work perfectly fine with this code inside of it
If you plan on using a ClientScript (LocalScript), it would probably be used for the player or using Services such as the UserInputService for example, which detects when a player presses something on their keyboard via mouse