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

Is there a a way to make this cooldown system work?

I made a button that has a cooldown, but everytime it is clicked during cooldown, it just starts the whole cooldown over again. Any ways to combat this?

function OnClicked()
wait(1)
script.Parent.BrickColor = BrickColor.new("Really red")
script.Parent.Running.Value = false
wait(60)--starts wait over again.
script.Parent.BrickColor = BrickColor.new("Lime green")
script.Parent.Running.Value = true
end

script.Parent.ClickDetector.MouseClick:connect(OnClicked)--everytime the button is clicked it starts wait over again.

1 answer

✓ Accepted answer

Need to add a debounce like this:

debounce = false

function OnClicked()
if debounce == false then
debounce = true
wait(1)
script.Parent.BrickColor = BrickColor.new("Really red")
script.Parent.Running.Value = false
wait(60)--starts wait over again.
script.Parent.BrickColor = BrickColor.new("Lime green")
script.Parent.Running.Value = true
debounce = false
end
end

script.Parent.ClickDetector.MouseClick:connect(OnClicked)--everytime the button is clicked it starts wait over again.

4 comments

0

What does the debounce do?

0

debounce makes sure it only triggers once and if it has already triggered it waits till its finish then resets it self.

0

that is very good to know

0

If you want to know a bit more about it: https://scriptinghelpers.org/glossary/Debounce

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