Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
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

0
Why is there so many scripts and parents? I don't understand StarzSketchez 31 — 4y
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 DuckyRobIox 280 — 4y
Ad
Log in to vote
0
Answered by
GITSTP 19
4 years ago
-- 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
0
I think this would work GITSTP 19 — 4y

Answer this question