Heyo!
I found myself needing to find out how much time has passed between two intervals quite often, so I made the process into a standardized, easy-to-use function. It ended up being pretty useful so I’ve decided to release it to the public!
How does it work?
After you require the module, you can call it and it will return a stopwatch
object. From there you can use these functions:
Returns the amount of time passed since the last reset
stopwatch()
Resets the starting time of the stopwatch
stopwatch:reset()
Usage Example
Here is an example of how the stopwatch could be used as a double jump debounce:
-- Services
local UIS = game:GetService('UserInputService')
-- Modules
local StopwatchCreator = require(game.ReplicatedStorage.Modules.Stopwatch)
-- Variables
local stopwatch = StopwatchCreator()
local doubleJumpCD = .5
UIS.JumpRequest:Connect(function()
if stopwatch() >= doubleJumpCD then
print('can double jump!')
stopwatch:reset()
else
print('cant double jump :(')
end
end)
Libary Link
What are you waiting for? Get it now!