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

How do you make a double click script for a TextButton?

Asked by 5 years ago

I'm trying to make a gui where if I double click within a span of 1s, it would do something else. I tried using this script, but it doesn't really work that well.

button.MouseButton1Click:Connect(function()
    local wantTo = true
    button.MouseButton1Click:Connect(function()
        if wantTo == true then
            --Double click script
        end
    end)
    wait(1)
    wantTo = false
    --Single click script
end)

1 answer

Log in to vote
1
Answered by 5 years ago

What your current script is doing:

On line 1, it listens for the MouseButton1Click event

On line 3, it’s overwriting the listener for line 1, thus line 1’s code not running

To fix this, add a counter and add +1 to it.

local counter = 0

button.MouseButton1Click:Connect(function()
    counter = counter + 1

    if counter == 2 then
        -- Code
    end
end)

Hope I helped.

0
Ah, I see. Thanks for the help :) SirDerpyHerp 262 — 5y
Ad

Answer this question