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

Is there a way to make a Click Detector cooldown?

Asked by 3 years ago
here is the code

local part = script.Parent local debounce = false

part.ClickDetector.MouseClick:Connect(function() part.Sign.SurfaceGui.TextLabel.Text = math.random(1, 8) debounce = true wait(6) debounce = false

end)

0
oops CrownedFigure 45 — 3y
0
im sorry that i forgot to press enter when i put debounce _ false CrownedFigure 45 — 3y

2 answers

Log in to vote
0
Answered by
megukoo 877 Moderation Voter
3 years ago

Yes. You're on the right track, you're just not utilizing the debounce correctly.

local part = script.Parent 
local debounce = false

part.ClickDetector.MouseClick:Connect(function() 
    if not debounce then -- This is the check we need.
        -- This will check if "debounce" is equal to false; when it is false, run this code, and we change it to true so that it won't activate while on cooldown.
        part.Sign.SurfaceGui.TextLabel.Text = math.random(1, 8) 
        debounce = true 
        wait(6) 
        debounce = false
    end
end)
1
Thanks for helping me! CrownedFigure 45 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Maybe something like this(Not sure):

CoolDown = false

function Example()

CoolDown = true

part.Sign.SurfaceGui.TextLabel.Text = math.random(1, 8) 

Wait(3)

CoolDown = false

end

function Clicked()

if CoolDown == false then

    Example()

end

end

Answer this question