
Sure, though I would recommend doing it by calulating the elapsed time since, as opposed to yielding a thread.
At that point just use task.delay()
task.delay(2, function()
Debounce = false;
end)
Much faster to write, and is basically the exact same thing.
1 Like
thx, bro! I had forgotten about this.
The implementation is fine but I recommend you use guard clauses instead of nesting. You can change your script to this to make it easier to read:
local Debounce = false
local function Activated()
if Debounce then
return
end
Debounce = true
task.delay(2, function()
Debounce = false
end)
end
Also fyi lua doesn’t need semicolons to determine when a line ends so you can save yourself some time by not explicitly writing them. They are only really useful when you want to fit multiple operations into a single line.