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

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

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

1 comment

0

MouseButton2Click is the right mouse button. You can use a BoolValue to check if it was clicked before. E.g. if clickedOnce then

2 answers

###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

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!

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