The 1st argument is NOT optional, on that :HasTag, :AddTag and :RemoveTag need to be usable (Mandatory)
The 2nd and 3rd arguments are optional (order doesn’t matter, as seen in the exampels)
If one of them is a string it will be used as tag and if it’s a number it will be used as await
tag is a string which will be used in giving your current debounce a name
await is the duration in seconds for how long the debounce should occur
If you don’t specify tag or/and await the default values are set as following:
local Replicated = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
local debounce = require(Replicated.handleDebounce)
script.Parent.TextButton.MouseButton1Click:Connect(function()
if (debounce:handle(player, 1, "exampleTag")) then
print("clicked")
else
warn("debounced")
end
end)
The if-statement would only be true if the instance has no active debounce. Which means if you spam click, it would only trigger every 3 seconds since the time set for the debounce is 3
If you are using the module with different purposes within the same script, you’d want to use tags in order to specify a unique debounce.
Also you aren’t forced to set a tag
(If it doesn’t, I’ll fix that. The idea of tags is the use of multiple debounces)
I know, in my example I provided a fixed wait. But in many scenarios, the amount of time you wait in the block is variable and so not appropriate for this module. But it’s quite simple to do a debounce anyway, so it seems a waste to have a module like this for something so simple when it only works half of the time.
As stated, if the contents of the block yields, this module is not suitable.
E.g:
local function SwingSword(special)
if debounce(player, 1) then
if special then
wait(2)
Hit() -- debounce is over prematurely
else
wait(0.5)
Hit() -- debounce is reasonable
end
end
end
It would be much easier to use a traditional debounce, which can be done very easily.