Hello,
I’m having a bit of a strange issue. I cannot get this debounce module working even though the code is almost directly our of the developer articles. Can anyone notice the issue here?
error: ServerScriptService.Examples.DebounceModule:8: attempt to call upvalue ‘func’ (a nil value)
Script
local myPart = game.Workspace.Part
local module = require(script.Parent:WaitForChild("DebounceModule"))
function onTouched(otherPart)
print("Part was touched by: " .. otherPart.Name)
end
myPart.Touched:Connect(module.debounce(onTouched))
Module
local module = {}
function module:debounce(func)
local isRunning = false -- Create a local debounce variable
return function(...) -- Return a new function
if not isRunning then
isRunning = true
func(...) -- Call it with the original arguments
isRunning = false
end
end
end
return module
Thanks for the help
Regards,
Nightcaller