Clock Library is a very powerful, effective, handy, complex but easy to understand Timer Library that will get rid of all need for any other Timer Library Module, designed and made by @Tironpc!
Why should i use Clock Library
Powerful and Effective Timers
99% Typechecked, but dont worry every useful info / type is fully implemented!
Useful in every scenario, being very Versatile and Compatible
Has a lot of Features, and more will get added over time
Beginner Friendly, having a Documentation and Tutorial on Github
This Library will be useful for a long period, listening to your suggestions and managing any bugs you encounter
OOP Based Library !
How do i use Clock Library
How to use
To use the Library all you have to do is get the module on the ROBLOX Creator Store:
Takes Snapshots perpetually until you stop it using StopPerpetualSnapshot(), you can change how
slow Snapshots are taken with the SnapshotDelayTime Parameter, by default the DelayTime is 0 meaning it Snapshots are taken very fast, and multiple times per second.
You can also make it so the Snapshot Sound does not play using the PlaySnapshotSound Parameter, both these Parameters are optional but if you wish to use their default value just input nil, or nothing at all.
StopPerpetualSnapshot()
Stops Perpetual Snapshotting.
Snapshot Changes:
Snapshot Changes
Made Snapshots safer to use, previously Snapshots were very unsafe sometimes not taking Snapshots properly, and making bad conversion between properties.
Now it’s much better.
Bug fixes:
Fixed bug where some ClockParams values if inputted nil, were not being set to their default value
Fixed bug where OnElapse Connection was not firing properly
Added Documentation, New Functions, Settings and ability to reverse a ClockInstance’s Timer!
Added Documentation
Added Documentation
Added important Documentation to Github to variables inside a ClockInstance that were previously not mentioned by me.
StartTime
Time in seconds that is the Duration (Set by SetDuration()) of a ClockInstance’s Timer or the “StartTime” of a ClockInstance’s Timer if not reversed, if ClockInstance is reversed it’s Timer will keep running until it reaches this variable.
TimeElapsed
Time that has passed since the start of a ClockInstance’s Timer.
RunningTime
Time within a ClockInstance’s Timer, not to be mistaken with TimeElapsed.
ElapsedStint
Time that has passed since the start of a ClockInstance’s Timer, is used to check if it’s higher than the ClockInstance’s Stint value
To fire the OnStint Connection, if greater than or equal to the Stint value it will fire the OnStint connection and be set back to 0 to try and fire the Connection again.
These variables are very important when it comes to a ClockInstance’s Timer.
New Functions
New Functions
ReverseClock()
Reverses Clock by making it’s Timer go from the default, StartTime (Duration set by SetDuration() → 0 to:
0 → StartTime. If Clock is already reversed when executing this function it will revert back to the default: StartTime → 0.
IsReversed()
Returns boolean that if true means the ClockInstance’s Timer is reversed, if false means it’s not reversed.
Returns: (boolean)
GetRunningTime()
Gets ands returns the ClockInstance’s Running Time variable ClockInstance.RunningTime which is the current Time within a ClockInstance’s Timer.
Returns: (number)
New ClockParams Settings
New ClockParams Settings
ShowUITextAsRunningTime
Shows UIText as the RunningTime variable inside a ClockInstance.
Note that the Text shown in the UIText will have used math.round() first, to round the RunningTime variable.
Ability reverse A ClockInstance’s Timer!
Ability reverse A ClockInstance's Timer!
You can now reverse a ClockInstance’s Timer, now what do i mean by this?
Normally and by default a ClockInstance’s Timer runs like this:
StartTime → 0 seconds.
But with this new feature you can make it’s Timer run like this:
0 seconds → ``StartTime`
Basically reversing it.
Feature being shown via video (Streamable website):
Bug Fixes, new UI Text Parameter and Once() Connection!
Added :Once() Connection to every Connection!
Fixed Bug where every :Wait() Connection wouldn’t fire.
Added UITextDecimalCount, which will display the number of Decimals given, if FormatTime is not provided! (Allows you to determine how many decimals you want, different from ShowUITextAsRunningTime which shows all Decimals. (Inputting 0, will leave a “.” at the end!)
Make sure to look at the Documentation on the Github page, it has all the main documentation that is not mentioned here, and looking through everything would take atleast less than 6 minutes
Addition of Reset() Function, resets ClockInstance’s Timer back to the start without needing to do:
ClockInstance:Restart()
ClockInstance:Pause() --> Immediatelly Pause after restarting effectively resetting Timer back to
its start Time.
Use cases:
ClockInstance:SetDuration(5)
ClockInstance:Start()
task.wait(1.5)
ClockInstance:Reset()
print(ClockInstance:GetTimeLeft()) --> Would print approximately 5 seconds, same result as the
code above BUT without the need of unnecessary steps.
Hey, I’ve just recently discovered this. In my opinion, this is way better than Mubinets’ RblxTimer module! No offense to them, but its got more features of which meets the necessity of my game! I’m working on a tower defense game, and I’m currently implementing the elevator system for the lobby. This system requires the changing of duration of the timer; of which RblxTimer didn’t have. So this module is perfect for that! Until the creator of RblxTimer has time to update theirs, I’ll be focusing on this module more.
Snapshotting is a feature designed to Travel back in time. It allows you to take “Snapshots” any time you want, saving your ClockInstance at that particular moment where you Snapshotted your ClockInstance.
Example:
local ClockInstance = ClockLibrary.CreateClock(ID, ClockParams)
ClockInstance:SetDuration(10)
ClockInstance:Start()
task.wait(3.3)
ClockInstance:TakeSnapshot() --> Takes Snapshot 3.3 seconds after starting, so Timer should be
-- at approximately 6.7 seconds.
task.wait(3.3)
print(ClockInstance:GetTimeLeft()) --> Would print approximately 3.4 seconds.
ClockInstance = ClockInstance:SetSnapshot() --> Sets Snapshot!
print(ClockInstance:GetTimeLeft()) --> Would print approximately 6.7 seconds.
--> Why 6.7 seconds? Because we snapshotted our ClockInstance when it's Timer was at 6.7
-- seconds!
This feature is really powerful to also use as a data feature, because you do not need to use SetSnapshot() to use a Snapshotted Instance, you could actually do:
local ClockInstance = ClockLibrary.CreateClock(ID, ClockParams)
ClockInstance:SetDuration(10)
ClockInstance:Start()
task.wait(3.3)
ClockInstance:TakeSnapshot() --> Takes Snapshot 3.3 seconds after starting, so Timer should be
-- at approximately 6.7 seconds.
ClockInstance.Snapshot --> Snapshotted Instance.
Of course this isn’t recommended but let’s say for example you want to store previous data of a Timer, you could do it like shown above.
In the future such Functions would be added to Snapshotting.
Overall its very useful and fun to use, and will be improved on / will have more Functionalities in the future!
Clock Params Settings :
Clock Params Settings
3 New settings:
SnapshotSound: Sound that plays when a Snapshot is taken.
ShowUITextAsPercentage: Shows Text on UI Text as a percentage instead of Time in seconds, kind of like a progress percentage until the ClockInstance’s Timer finishes.
RestartOnFinish: Restarts ClockInstance’s Timer when it finishes.
Queue System :
Queue System
Previously all ClockInstance’s Timers where ran individually decreasing some performance on the Library, now the Library is even faster! Since it now works on a Queue System.
This Queue System works on 1 factor:
It only runs if ClockInstances exist, if none exists then it will wait until any exists before re-running the Queue.
If String Parameter is true returns as a string: "PercentageNumber%" else returns: PercentageNumber that is not a string.
--------------------------------------------
SetSnapshot()
Parameters: none
Returns: (ClockInstance)
Sets Snapshotted ClockInstance as the new ClockInstance, returns the Snapshotted ClockInstance
so you can Re-set your variable inside you code like so:
local ClockInstance = ClockLibrary.CreateClock(ID, ClockParams)
ClockInstance:TakeSnapshot()
ClockInstance = ClockInstance:SetSnapshot()
--> And i can still do normal ClockInstance Functions and i have every setting that was previously
-- set like: Time, Speed and any setting existing in a ClockInstance.
--------------------------------------------
TakeSnapshot()
Parameters: none
Returns: none
Takes Snapshot of current ClockInstance to then be set using SetSnapshot()
Pauses after X amount of Seconds, and Resumes After X amount of Seconds after pausing if given ResumeAfter variable.
--------------------------------------------
DecreaseTime()
Parameters: (Time: number)
Returns: none
Decreases ClockInstance’s Timer by the given Time parameter.
--------------------------------------------
SetSpeed()
Parameters: (Speed: number)
Returns: none
Sets Speed of ClockInstance’s Timer.
Speed Modifier :
Speed Modifier
Speed Modifier is a setting inside a ClockInstance that determines how fast it’s Timer runs.
This Speed Modifier is defaulted to 1, meaning it does not affect your ClockInstance’s Timer.
EX:
--> Scenario 1
local ClockInstance = ClockLibrary.CreateClock(ID, ClockParams)
ClockInstance:SetDuration(5)
ClockInstance:Start() -- After 5 seconds would end Timer!
--> Scenario 2
local ClockInstance = ClockLibrary.CreateClock(ID, ClockParams)
ClockInstance:SetDuration(5)
ClockInstance:SetSpeed(2)
ClockInstance:Start() -- After 2.5 seconds would end Timer!
This Speed Modifier is used to manipulate how Time behaves and runs in your ClockInstance Timers, trust me it’s very useful!
Deprecated Functionalities :
Deprecated Functionalities
OnInterval Connection
First of all you might be asking why deprecate such a, for the most part useful feature?
Well it’s very unreliable, thats why in the next update it will be replaced with a better Connection Type that is almost identical to it.
Now why is it unreliable? Because of how it handled Intervals which wasn’t the best and sometimes hampered with other ClockInstances!
If you are using this Connection this is just a reminder that in the next update this Connection will be replaced!
Existing Function Changes :
Existing Function Changes
Pause(): New Parameter → ResumeAfter: number?
If given, resumes ClockInstance’s Timer after X amount of seconds.
Resume(): New Parameter → PauseAfter: number?
If given, pauses ClockInstance’s Timer after X amount of seconds.
Hello, when creating a new clock instance while providing ClockParams, it doesn’t seem to apply? For Interval that is, because when I tried printing timer.Interval it says 0. So manually I’d have to do timer:SetInterval() instead.
It’s because it actually sets it to 0, automatically, i will release an update real soon to replace the OnInterval connection for a better one and some small patches to the Module.
While i work on a better connection you could do this if you wish to replicate OnInterval:
local ClockInstance = ClockLibrary.CreateClock(ID, ClockParamas)
local IntervalTimer = os.clock()
local RequiredTime = -2.5
ClockInstance:SetDuration(5)
ClockInstance:Start()
ClockInstance.OnElapse:Connect(function()
if IntervalTimer - os.clock() <= RequiredTime then
-- Do your code!
end
end)
Github fully updated, i added a Troubleshotting and Feedback discussion pages + updated Documentation and made the ClockInstance tutorial a bit better.
Takes Snapshots perpetually until you stop it using StopPerpetualSnapshot(), you can change how
slow Snapshots are taken with the SnapshotDelayTime Parameter, by default the DelayTime is 0 meaning it Snapshots are taken very fast, and multiple times per second.
You can also make it so the Snapshot Sound does not play using the PlaySnapshotSound Parameter, both these Parameters are optional but if you wish to use their default value just input nil, or nothing at all.
StopPerpetualSnapshot()
Stops Perpetual Snapshotting.
Snapshot Changes:
Snapshot Changes
Made Snapshots safer to use, previously Snapshots were very unsafe sometimes not taking Snapshots properly, and making bad conversion between properties.
Now it’s much better.
Bug fixes:
Fixed bug where some ClockParams values if inputted nil, were not being set to their default value
Fixed bug where OnElapse Connection was not firing properly
Added Documentation, New Functions, Settings and ability to reverse a ClockInstance’s Timer!
Added Documentation
Added Documentation
Added important Documentation to Github to variables inside a ClockInstance that were previously not mentioned by me.
StartTime
Time in seconds that is the Duration (Set by SetDuration()) of a ClockInstance’s Timer or the “StartTime” of a ClockInstance’s Timer if not reversed, if ClockInstance is reversed it’s Timer will keep running until it reaches this variable.
TimeElapsed
Time that has passed since the start of a ClockInstance’s Timer.
RunningTime
Time within a ClockInstance’s Timer, not to be mistaken with TimeElapsed.
ElapsedStint
Time that has passed since the start of a ClockInstance’s Timer, is used to check if it’s higher than the ClockInstance’s Stint value
To fire the OnStint Connection, if greater than or equal to the Stint value it will fire the OnStint connection and be set back to 0 to try and fire the Connection again.
These variables are very important when it comes to a ClockInstance’s Timer.
New Functions
New Functions
ReverseClock()
Reverses Clock by making it’s Timer go from the default, StartTime (Duration set by SetDuration() → 0 to:
0 → StartTime. If Clock is already reversed when executing this function it will revert back to the default: StartTime → 0.
IsReversed()
Returns boolean that if true means the ClockInstance’s Timer is reversed, if false means it’s not reversed.
Returns: (boolean)
GetRunningTime()
Gets ands returns the ClockInstance’s Running Time variable ClockInstance.RunningTime which is the current Time within a ClockInstance’s Timer.
Returns: (number)
New ClockParams Settings
New ClockParams Settings
ShowUITextAsRunningTime
Shows UIText as the RunningTime variable inside a ClockInstance.
Note that the Text shown in the UIText will have used math.round() first, to round the RunningTime variable.
Ability reverse A ClockInstance’s Timer!
Ability reverse A ClockInstance's Timer!
You can now reverse a ClockInstance’s Timer, now what do i mean by this?
Normally and by default a ClockInstance’s Timer runs like this:
StartTime → 0 seconds.
But with this new feature you can make it’s Timer run like this:
0 seconds → ``StartTime`
Basically reversing it.
Feature being shown via video (Streamable website):
Oh! I will fix this, i have been using this module from time to time, but haven’t messed in it for a while, i will fix this and get back with an update, any other things you may like in the module?
Bug Fixes, new UI Text Parameter and Once() Connection!
Added :Once() Connection to every Connection!
Fixed Bug where every :Wait() Connection wouldn’t fire.
Added UITextDecimalCount, which will display the number of Decimals given, if FormatTime is not provided! (Allows you to determine how many decimals you want, different from ShowUITextAsRunningTime which shows all Decimals. (Inputting 0, will leave a “.” at the end!)