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

How to make a GUI Button that when click shows a frame and when clicked again it makes it invisible?

Hello, here is a short explanation. So, I want to create a GUI Button for my game that opens a frame when clicked, and when clicked again it makes the same frame invisible,

Here is the script that I made:


-- Variables

local clicked = 0
local updateLog = script.Parent.UpdateLogButton
local updateLogFrame = script.Parent.Title

-- Script

updateLog.MouseButton1Click:Connect(function()
	
			clicked = clicked + 1
	
	updateLog.MouseButton1Click:Connect(function()

		if clicked == 1 then
			
			updateLogFrame.Visible = true
			
		end
		
		if clicked == 0 then
			
			updateLogFrame.Visible = false
			
		end
		
		if clicked == 2 or clicked <= 1 then
				
			clicked = 0
				
		end
		
	end)

end)

It seemed to work fine at the start, when I clicked it, it showed the frame and when I clicked it again it made the frame invisible, but when I tried clicking it again (After it made the Frame Invisible.) it did not work ( It didn't make the frame visible again. ). Please help me solve this problem.

2 answers

✓ Accepted answer
function onClick()

if (script.Parent.Parent.Parent.updateLogFrame.Visible)then
	
	script.Parent.Parent.Parent.updateLogFrame.Visible = false
	
else
	
	script.Parent.Parent.Parent.updateLogFrame.Visible = true
	
	end
end

script.Parent.MouseButton1Down:Connect(onClick)

Fix the parents to the amount but this should work accept if so ask help if doesn't

2 comments

0

Why is there so many scripts and parents? I don't understand

0

Ok So if you have a screengui thats 1 parent if you have a frame in that screengui thats 2 parents so if updatelogframe is in the 2nd frame and you wanna open it you put 3 parents

-- Varibles

local updateLog = script.Parent.UpdateLogButton
local updateLogFrame = script.Parent.Title

-- Scripts

if updateLog.Text == "Open" then
	updateLog.MouseButton1Click:Connect(function()
		updateLogFrame.Visible = true
		updateLog.Text = "Close"
	end)
end

if updateLog.Text == "Close" then
	updateLog.MouseButton1Click(function()
		updateLogFrame.Visible = false
		updateLog.Text = "Open"
	end)
end

1 comment

0

I think this would work

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