How to make a gui close when you click it

  1. What do you want to achieve?
    I want to close the gui when second click is made (1st one opens it, 2nd one close it)
  2. What is the issue?
    I don´t know how it’s done
  3. What solutions have you tried so far?
--//Services//--
local Tween = game:GetService("TweenService")

--//Frame Variables//--
local CharacterSelectFrame = script.Parent:WaitForChild("CharacterSelectFrame")

--//Variables//--
local NarutoCharacterSelect = CharacterSelectFrame:WaitForChild("NarutoCharacterSelect")
local SelectCharacter = script.Parent:WaitForChild("SelectCharacter")

--//Tweens//--
local CSFPopIn = Tween:Create(CharacterSelectFrame, TweenInfo.new(0.3, Enum.EasingStyle.Sine), {Transparency = 0.5})
local CSFPopOut = Tween:Create(CharacterSelectFrame, TweenInfo.new(0.3, Enum.EasingStyle.Sine), {Transparency = 1})
local NCSPopIn = Tween:Create(NarutoCharacterSelect, TweenInfo.new(0.3, Enum.EasingStyle.Sine), {TextTransparency = 0})
local NCSPopOut = Tween:Create(NarutoCharacterSelect, TweenInfo.new(0.3, Enum.EasingStyle.Sine), {TextTransparency = 1})
--//SelectCharacter//--
SelectCharacter.MouseButton1Click:Connect(function()
	CSFPopIn:Play()
	NCSPopIn:Play()
end)

SelectCharacter.MouseButton2Click:Connect(function()
	CSFPopOut:Play()
	NCSPopOut:Play()
end)

Thank you in advance for answering.
If my question already has an obvious answer, then I apologize for my ignorance.

1 Like

For the frame holding the character selection buttons you wanna either make it not visible, change the size to a smaller size, or move it off the screen with position

I want to close a menu when you left click on it, but that menu has been opened before by left clicking.

Are you trying to open/close the GUI with the same button element? If so, you can easily do that with a boolean variable. I would create one like this: local IsGuiOpen = false. When you left click on the button, assign IsGuiOpen to the negation of itself: IsGuiOpen = not IsGuiOpen. This flips it like a lightswitch from on to off, or vice versa. Then, do a conditional to either open or close the GUI depending on what IsGuiOpen is set to:

if IsGuiOpen then
   --Open()
else
   --Close()
end

Like this?

--//Services//--
local Tween = game:GetService("TweenService")

--//Frame Variables//--
local CharacterSelectFrame = script.Parent:WaitForChild("CharacterSelectFrame")

--//Variables//--
local NarutoCharacterSelect = CharacterSelectFrame:WaitForChild("NarutoCharacterSelect")
local SelectCharacter = script.Parent:WaitForChild("SelectCharacter")
local CSFIsOpen = false

--//Tweens//--
local CSFPopIn = Tween:Create(CharacterSelectFrame, TweenInfo.new(0.3, Enum.EasingStyle.Sine), {Transparency = 0.5})
local CSFPopOut = Tween:Create(CharacterSelectFrame, TweenInfo.new(0.3, Enum.EasingStyle.Sine), {Transparency = 1})
local NCSPopIn = Tween:Create(NarutoCharacterSelect, TweenInfo.new(0.3, Enum.EasingStyle.Sine), {TextTransparency = 0})
local NCSPopOut = Tween:Create(NarutoCharacterSelect, TweenInfo.new(0.3, Enum.EasingStyle.Sine), {TextTransparency = 1})

--//SelectCharacter//--
SelectCharacter.MouseButton1Click:Connect(function()
	CSFIsOpen = not CSFIsOpen
	if CSFIsOpen then
		--//Open//--
		local CSFPopIn = Tween:Create(CharacterSelectFrame, TweenInfo.new(0.3, Enum.EasingStyle.Sine), {Transparency = 0.5})
		local NCSPopIn = Tween:Create(NarutoCharacterSelect, TweenInfo.new(0.3, Enum.EasingStyle.Sine), {TextTransparency = 0})
	else
		--//Close//--
		local CSFPopOut = Tween:Create(CharacterSelectFrame, TweenInfo.new(0.3, Enum.EasingStyle.Sine), {Transparency = 1})
		local NCSPopOut = Tween:Create(NarutoCharacterSelect, TweenInfo.new(0.3, Enum.EasingStyle.Sine), {TextTransparency = 1})
	end	
end)

Sorry if it´s an obvious answer and I don´t understand it, I apologize for my ignorance.

That looks good with my first glance.
MouseButton1Click → Toggle boolean → Open or close depending on the value.
All you gotta do is change the conditional to actually play the tweens you created:

SelectCharacter.MouseButton1Click:Connect(function()
	CSFIsOpen = not CSFIsOpen
	if CSFIsOpen then
		--//Open//--
		CSFPopIn:Play()
		NCSPopIn:Play()
	else
		--//Close//--
		CSFPopOut:Play()
		NCSPopOut:Play()
	end	
end)

You already created the tweens under --//Tweens//--, so there’s no need to re-initialize them; just play them here.

Ah, I misread some of what you where trying to do. @Storm_SJ

but like @Ancientroboman stated with a boolean should work.
Good Luck!