0

# How do I add a click cooldown to this script?

I want to add a cooldown to a tool so it cannot be spammed.

script.Parent.Equipped:connect(function(mouse)
mouse.Button1Down:connect(function()
script.Parent.Input:FireServer('Mouse1', true, mouse.Hit)
end)
end)


0
Edited 7 days ago

The most common form of cooldown of this type is usually called a debounce, which is actually fairly easy to implement once you learn about it.

local debounce = true
script.Parent.Equipped:connect(function(mouse)
mouse.Button1Down:connect(function()
if debounce == true then
debounce = false
script.Parent.Input:FireServer('Mouse1', true, mouse.Hit)
wait(1)--put the cooldown you want here
debounce = true
end
end)
end)


When the script is called, it checks if the debounce is true, if it is then you set the debounce to false, go through with whatever code you want, wait a time, then set it back to true. This makes it so that it can't activate again until debounce is set back to true.

0
It worked, thank you so much. ippiya 2 — 7d