How should I make an advanced round countdown timer?

For now, my countdown system fundamentally sets an attribute (placed in workspace) named ‘timer’ every second.
and client gets timer changing event with :GetAttributeChangedSignal() and display the time.

But I want it to have more features like:

  • UI displays decimal point when the remaining time is lower than 10 seconds.
  • the timer could pause or reset in VIP servers.
  • more performanted.

I think my countdown system can’t do these things, and needs a new method.
I’m not saying I want whole completed code, I’m just curious about what kind of structure this should be made of.

Basically just send a number over a remote event. When a player gets it have their system record the start as the current tick(). Then you can check it with tick() - startTick to get the amount of time left with decimal precision.

This will let you change to have decimals when you want, and you can round the rest of the time.

As for point 2 and 3. Just send a pause command to stop the timer (like a, secondsLeft, true) where the true means to pause the timer so the client code knows to stop. And this is technically more performant or less depending on what you mean. You’ll probably be checking this every frame which is doing more work per frame, but you probably won’t be using nearly as much internet which will make it more efficient. Also the amount of work this adds per frame is negligible.

A note that is probably overkill.

Though it’s worth noting that there will be latency when you send it so the timer will technically be off. Ideally though it will have the same latency as everything else so it will look accurate anyways. But it’s possible that message in particular comes late or early compared to the normal network conditions. You can account for this probably by trying to send the server time along as well and use the :GetServerTimeNow() function. But that’s probably overkill since at most you will be off by like 0.1-0.4 seconds unless the player has really bad internet. (note that this will be off too, but potentially less so)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.