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

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)

1 answer

✓ Accepted answer

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.

1 comment

0

It worked, thank you so much.

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