Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I get 2 close buttons to work with each other simultaneously?

For my UI menu I have 2 buttons. Button 1 is to open and close the menu, and button 2 is a close button on the menu to close the menu, however I am having some issues with this. This is because, for the script for button 1 I have this:

local open = false
codeButton.MouseButton1Up:Connect(function()
	GuiSound:Play()
	if open == false then
		openGui()
		open = true
	elseif open == true then
		closeGui()
		open = false
	end
end)

But when button 2 is pressed, and closes the menu, the script for button 1 still thinks the menu is open meaning I have to click button 1 twice to open the menu back up again because it thinks open = true, how would I fix this without the use of global variables?

1 answer

✓ Accepted answer

Don't use a variable for this when you can simply use the Visible property of your menu to check if it's open.

local guiObject = script.Parent
local button = script.Parent.Parent.Button
local Visible = guiObject.Visible

button.MouseButton1Click:Connect(function()
	if Visible == true then
		Visible = false -- or use your custom function
	else
		Visible = true -- or use your custom function
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.