I have a function to handle debounces in its own separate module that is referenced inside my main framework module and can be referenced at any time.
Here is the debounce code from the module:
function Debounce.DebounceFunc(func)
local isRunning = false
return function(...)
if isRunning then return end
isRunning = true
func(...)
isRunning = false
end
end
Here is a snippet of code where the debounce function is being used in a touched event. The problem is, the debounce doesn't seem to do anything, and the event is fired many times a second:
function Fire:Burn()
self:Tick()
self.Parent.Touched:connect(Framework.Debounce(function(hit)
print(true)
end))
end
Just in case people ask, here is the snippet of code in my framework module referencing the debounce module:
-- Server
if not MainFramework.LocalPlayer then
MainFramework.Debounce = MainFramework.Modules.Debounce.DebounceFunc
end
Should also note that the framework handles the requiring of the modules so that isn't an issue either.
Any tips appreciated, can't tell if there's just some incorrect logic, or if I'm applying the function to the event wrong or what.

1 comment
Touched events are horrible and can clump threads together so tightly that they can bypass a debounce. If you really need an accurate touched event, then go with region3 instead and run it through a loop. If you're worried about resource consumption, you can always mitigate when the loop for the region3 fires.