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

How do I add a clicking delay in my treecutting system?

Asked by
Fako16 13
6 years ago

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

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
6 years ago

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)
0
Thanks for your answer! It works now! Fako16 13 — 6y
Ad

Answer this question