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

Event fired when clicked again?

Asked by 10 years ago

I can't find this event on the ROBLOX wiki so i'll ask here.

What's the event that fires AFTER the player clicks a button the 2nd time? For example, if they click a button to make a GUI visible i want them to click it again to close it.

3 answers

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

You'd use MouseButton1Down or MouseButton1Click. If you want it to close, use a variable.

open = false
vis = script.Parent.Parent -- Should lead to what you want to be Visible/Invisible
sp = script.Parent 

sp.MouseButton1Down:connect(function()
    if not open then
        open = true
        vis.Visible = true
    elseif open then
        open = false
        vis.Visible = false
    end
end)
Ad
Log in to vote
0
Answered by
Sublimus 992 Moderation Voter
10 years ago

There is no event to check if a player has clicked again. But there is a way you can do what you are talking about using variables:

open = false -- Gui is invisible by default
gui = script.Parent.Parent -- Assuming script.Parent.Parent is a Frame or something that has a visible property, you can change this of course
script.Parent.MouseButton1Down:connect(function() -- Assuming script.Parent is the button
    if open == false then -- If the gui isn't open
        gui.Visible = true -- Make the gui visible
        open = true -- Set the open variable to true
    else -- If it is open
        gui.Visible = false -- Make it invisible
        open = false -- Set the open variable to false
    end -- End the if statement
end) -- End the function
0
Funny. We used the same 'open' variable. Gg. Shawnyg 4330 — 10y
0
Yep, gg. Sublimus 992 — 10y
Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago
local gui = script.Parent.Parent:WaitForChild("Frame")
local button = script.Parent

button.MouseButton1Click:connect(function()
    gui.Visible = not gui.Visible
    -- Makes it the opposite of what it currently is.
    button.Text = (gui.Visible and "Close" or "Open")
    -- Ternary operation to shorten it. 
        --[[ 
        if gui is visible then 
            -- make the text Close
        --else
            -- make the text Open
        --]]        
end)

Answer this question