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 clicking delay in my treecutting system?

Hello guys, I'm Fako16 and I'm working on a tree-cutting system to show my friends! I have made the tree-cutting system, but there's a problem of Auto-clicking, does anyone know how do I make it so no one can spam the wood? Is there a way to do that? The OnClick script bassicaly just gives him +1 Wood, but it can be spammed. Please help me out, any help is appreciated, THANKS!

1 answer

✓ Accepted answer

Add a debounce.

It's basicly an extra if statement that only allows the function / event to run once every "given" seconds.

Here's an example.

local Debounce = false
local function Chop()
	if Debounce then return end
	Debounce = true
	
	--Your code
	
	Wait(TimeBeforeUsableAgain)
	Debounce = false
end

Tree.mouseClick:Connect(Chop)

1 comment

0

Thanks for your answer! It works now!

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