Clock Library - Timer Library (V -> 1.1.75)

— { Clock Library: The Only Timer Library you will ever need! } —

GET CLOCK LIBRARY HERE :

:grey_question: What is Clock Library :grey_question:

  • 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!

:grey_question: Why should i use Clock Library :grey_question:

  • Powerful and Effective Timers :white_check_mark:

  • 99% Typechecked, but dont worry every useful info / type is fully implemented! :exclamation:

  • Useful in every scenario, being very Versatile and Compatible :dizzy:

  • Has a lot of Features, and more will get added over time :boom:

  • Beginner Friendly, having a Documentation and Tutorial on Github :+1:

  • This Library will be useful for a long period, listening to your suggestions and managing any bugs you encounter :grey_exclamation: :exclamation:

  • OOP Based Library ! :brain:

:grey_question: How do i use Clock Library :grey_question:

How to use

To use the Library all you have to do is get the module on the ROBLOX Creator Store:

Clock Library Asset

Or do this:

Inser the RBX File into your game, preferrably in ReplicatedStorage or Server-Side:

RBX Script File Clock Library (1.1.75).rbxm (13.6 KB)

Documentation :bookmark_tabs:

Patch Notes :brain: :scroll:

[details=" Patch Notes"]

V → 1.1.5

V 1.1.5

The Connections Update

Hello fellow Devs, update V → 1.1.5 is here and it massively overhauls one feature of the ClockLibrary:

Connections

Connections

Previously all Connections ran together sort of like a Queue System, which worked very well but had 2 issues:

  1. They sometimes clogged themselves up leading to sometimes not firing anything, which rarely happened but still should be avoided.

  2. They fired simultaneously, with could (only in rare occasions) cause lag spikes in the future or for big projects.

Now they fire sequentially (Not Parallel Luau)

They also fire on a small delay that is almost impossible to notice while still making sure each connection fires!

This also improves performance of the Library by a lot, even though it is very lag-free!
Now this isn’t the only change:

Connections can send arguments to Connected Functions!
Like OnElapse and the new OnStint Connection!

They both send 2 arguments to Connected Functions:

deltaTime: number, Time in between each frame.

TimeLeft: number | string, Time Left until the ClockInstance’s Timer finishes.

New Connections:

New Connections

OnStint

Fires every X amount of seconds within a ClockInstance’s Timer based on the Stint variable inside a ClockInstance.

This OnStint Connection is also the 1 (First) Connection that will fire.
(This is the replacement of the OnInterval Connection)

OnStart

Fires when a ClockInstance starts it’s Timer (Not restarting)

OnSleep

Fires when a ClockInstance sleeps, a ClockInstance sleeps when:

  1. 2 Seconds after it finishes it’s Timer.

  2. When reset by the Reset() Function

------------

  • Small Tweaks:

  1. Queue System slightly changed (to fit with new Connection System)

  2. Updated some Types

  3. Small optimization Changes.

Get Version → 1.1.5 here:

Clock Library Asset

Or the RBX Script File:

Clock Library.rbxm (12.3 KB)

--------------------------------------------------------------

V → 1.1.6

1.1.6

Snapshot Changes :camera_flash:

New Functions:

New Functions

PerpetuallySnapshot(SnapshotDelayTime: number?, PlaySnapshotSound: boolean?)

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:

  1. Fixed bug where some ClockParams values if inputted nil, were not being set to their default value
  2. Fixed bug where OnElapse Connection was not firing properly

Get Version → 1.1.6 here:

Clock Library Asset

Or the RBX Script File:

Clock Library.rbxm (12.7 KB)

--------------------------------------------------------------

V → 1.1.75

1.1.75

Added Documentation, New Functions, Settings and ability to reverse a ClockInstance’s Timer!

Added Documentation :green_book:

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 :gear:

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 :screwdriver:

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! :clock330:

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):

Reversal Feature Showcase

New Connection Parameters

New Connection Parameters

OnElapse and OnStint connections have a new Parameter, that is replacing previous deltaTime Parameter.

RunningTime: RunningTime Variable of the ClockInstance.

Get Version → 1.1.75 here:

Clock Library Asset

Or the RBX Script File:

Clock Library (1.1.75).rbxm (13.6 KB)

--------------------------------------------------------------

CLOCK LIBRARY DOWNLOADS

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

Clock Library Documentation

Thanks for the read, and have fun using this very useful Module!

Im open to any suggestions and bugs, so please comment and reply to this post with your suggestion / bug!

14 Likes

I don’t really think I would use this for a real game, but this is a cool contribution to the community, keep it up

Thanks, in a real game in a scenario where you would need it this Library would do the job very well but thanks for the reply!

2 Likes

V → 1.0.1

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.
1 Like

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. :slight_smile:

1 Like

Thanks! Any suggestions or ideas you want i will implement them since i will be very active here.
Feedback is always appreciated.

A big update is coming in 1-2 days so stay tuned, it will massively improve this Module keep your expectations high!

Edit:

Update V → 1.1 is releasing in approximately 2-3 hours!

1 Like

V → 1.1 IS HERE:

1.1

Snapshotting :camera_flash::

Snapshotting

Hello, hello Snapshotting is hereeeee!

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 :gear::

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 :walking_man::

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. :white_check_mark:

This Queue System works on 1 factor:

  1. It only runs if ClockInstances exist, if none exists then it will wait until any exists before re-running the Queue.

New Functions :scroll::

New Functions

GetTimeLeftAsPercentage()

Parameters: (String: boolean?)
Returns: (number | string)

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()

--------------------------------------------

ResumeOn()

Parameters: (Seconds: number, PauseAfter: number?)
Returns: none

Resumes after X amount of Seconds, and Pauses After X amount of Seconds after resuming if given PauseAfter variable.

--------------------------------------------

PauseOn()

Parameters: (Seconds: number, ResumeAfter: number?)
Returns: none

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 :dash::

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 :frowning_face::

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 :screwdriver::

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.

Get Version → 1.1 here:

Clock Library Asset

Or the RBX Script File:

Clock Library.rbxm (12.0 KB)

Enjoy!!!
Documentation will be updated soon.

1 Like

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.

2 Likes

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.

Update should be out within the next 2-3 hours

1 Like

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)
1 Like

V → 1.1.5

The Connections Update

Hello fellow Devs, update V → 1.1.5 is here and it massively overhauls one feature of the ClockLibrary:

Connections

Connections

Previously all Connections ran together sort of like a Queue System, which worked very well but had 2 issues:

  1. They sometimes clogged themselves up leading to sometimes not firing anything, which rarely happened but still should be avoided.

  2. They fired simultaneously, with could (only in rare occasions) cause lag spikes in the future or for big projects.

Now they fire sequentially (Not Parallel Luau)

They also fire on a small delay that is almost impossible to notice while still making sure each connection fires!

This also improves performance of the Library by a lot, even though it is very lag-free!
Now this isn’t the only change:

Connections can send arguments to Connected Functions!
Like OnElapse and the new OnStint Connection!

They both send 2 arguments to Connected Functions:

deltaTime: number, Time in between each frame.

TimeLeft: number | string, Time Left until the ClockInstance’s Timer finishes.

New Connections:

New Connections

OnStint

Fires every X amount of seconds within a ClockInstance’s Timer based on the Stint variable inside a ClockInstance.

This OnStint Connection is also the 1 (First) Connection that will fire.
(This is the replacement of the OnInterval Connection)

OnStart

Fires when a ClockInstance starts it’s Timer (Not restarting)

OnSleep

Fires when a ClockInstance sleeps, a ClockInstance sleeps when:

  1. 2 Seconds after it finishes it’s Timer.

  2. When reset by the Reset() Function

------------

  • Small Tweaks:

  1. Queue System slightly changed (to fit with new Connection System)

  2. Updated some Types

  3. Small optimization Changes.

Get Version → 1.1.5 here:

Clock Library Asset

Or the RBX Script File:

Clock Library.rbxm (12.2 KB)

1 Like

Github fully updated, i added a Troubleshotting and Feedback discussion pages + updated Documentation and made the ClockInstance tutorial a bit better.

1 Like

V → 1.1.6

Snapshot Changes :camera_flash:

New Functions:

New Functions

PerpetuallySnapshot(SnapshotDelayTime: number?, PlaySnapshotSound: boolean?)

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:

  1. Fixed bug where some ClockParams values if inputted nil, were not being set to their default value

  2. Fixed bug where OnElapse Connection was not firing properly

Get Version → 1.1.6 here:

Clock Library Asset

Or the RBX Script File:

Clock Library.rbxm (12.7 KB)

1 Like

V → 1.1.75

Added Documentation, New Functions, Settings and ability to reverse a ClockInstance’s Timer!

Added Documentation :green_book:

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 :gear:

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 :screwdriver:

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! :clock330:

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):

Reversal Feature Showcase

New Connection Parameters

New Connection Parameters

OnElapse and OnStint connections have a new Parameter, that is replacing previous deltaTime Parameter.

RunningTime: RunningTime Variable of the ClockInstance.

Get Version → 1.1.75 here:

Clock Library Asset

Or the RBX Script File:

Clock Library (1.1.75).rbxm (13.6 KB)