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

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

Asked by 8 years ago

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

Log in to vote
1
Answered by 8 years ago

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.
0
What does the debounce do? connor12260311 383 — 8y
0
debounce makes sure it only triggers once and if it has already triggered it waits till its finish then resets it self. AdministratorGnar 25 — 8y
0
that is very good to know connor12260311 383 — 8y
0
If you want to know a bit more about it: https://scriptinghelpers.org/glossary/Debounce AdministratorGnar 25 — 8y
Ad

Answer this question