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

Is there a debounce for GUI Buttons?

Asked by
NecoBoss 194
10 years ago

I am making a text button and I only want it clicked once every 2 seconds. Is there a debounce for GUI's like there are for parts?

3 answers

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

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

Sort of... I wouldn't call it exactly debounce, but this sets a value to true and false so it doesn't allow them to click it again for 2 seconds. It basically does the same thing debounce would on a brick, except with some extra coding.

val = script.Parent.Able -- Name a bool value "Able"
val = false
script.Parent.MouseButton1Down:connect(function()
    if val == false then
    --What it's supposed to do here
    val = true
    wait(2)
    val = false
    else
    end
end)
Ad
Log in to vote
1
Answered by 10 years ago

You can use debounces for everything.

Log in to vote
0
Answered by
Ekkoh 635 Moderation Voter
10 years ago

Debounces aren't limited to parts. It's just a matter of disabling and re-enabling a function to run. If you want to make one for a TextButton, I'd do something like this-

local btn = script.Parent
local enabled = true

btn.MouseButton1Click:connect(function() -- when the button is clicked
    if enabled then -- if it is enabled
        enabled = false -- disable the button
        -- execute your code
        wait(2) -- wait 2 seconds after a click
        enabled = true -- re-enable the button
    end
end)

Answer this question