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

How to preform two functions with different numbers of clicks for a GUI?

Asked by 5 years ago
Edited 5 years ago

I have a GUI that I want to run two functions: Change the border color and make another GUI visible. Although it runs the first function, It won't run the second. This is the script:

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.BorderColor3=Color3.new(0,0,0)

end)

script.Parent.MouseButton2Click:Connect(function()
    script.Parent.BorderColor3=Color3.new(255,255,255)
    script.Parent.Parent.Parent.File.Visible=true
end)

--File is a frame under a ScreenGui
0
MouseButton2Click is the right mouse button. You can use a BoolValue to check if it was clicked before. E.g. if clickedOnce then User#22219 20 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

Use a counter to do this.

local counter = 0 -- clicked 0 times right now...

script.Parent.MouseButton1Click:Connect(function()
    counter = counter + 1
    script.Parent.BorderColor3 = Color3.fromRGB(0,0,0)

    if counter == 2 then
        script.Parent.BorderColor3=Color3.fromRGB(255,255,255)
        script.Parent.Parent.Parent.File.Visible=true
    end
end)

--File is a frame under a ScreenGui

Ad
Log in to vote
0
Answered by
Lugical 425 Moderation Voter
5 years ago
local debounce = true
script.Parent.MouseButton1Click:Connect(function()
if debounce == true then debounce = false
    script.Parent.BorderColor3=Color3.new(0,0,0)
end
end)
script.Parent.MouseButton2Click:Connect(function()
if debounce == false then debounce = true
    script.Parent.BorderColor3=Color3.new(255,255,255)
    script.Parent.Parent.Parent.File.Visible=true
end
end)


From what I'm understanding, the first function is playing, while the second is not. The cause of that is because every time the user registers the click, it'll count at MouseButton1Click. To combat this, I used a simple debounce so every time you click it'll rotate between the first and second function. Hopefully this works for you!

Answer this question