Alternatives To tick()?

I have heard that tick() is being deprecated sooner or later, so I have tried avoiding using it. I am now in a situation where I need an alternative to tick() and I have no idea on what to use.

I have tried:
os.time() - No decimal
os.clock() - Not based on UNIX epoch and also not efficient

So, what is an alternative to tick() that functions in the same way but will not be deprecated? (I am fine with creating my own function if I have to, I would just like to know how)

Thanks!

2 Likes

You would be looking at os.clock() for something similar, essentially functions the same way (at least in what its mostly used for in math) but its more precise, and based on the CPU time.

os.time() would the closest to tick(), but without decimals, and based on UTC time, rather than Device local time like tick().

Those are the MAIN alternatives you can use.

You can also use DataTime.now() for decimals, however its not as precise as others, only going to the thousandths place.

Really? Where have you heard that? tick() should not be deprecated.

2 Likes

says tick is going to be deprecated in the future.

I basically wrote this already:

But thanks for the extra detail.

Do you mean DateTime.now() ? Anyway, this doesn’t seem to have a decimal for me when I print it to the console.

Use DateTime.now().UnixTimestampMillis / 1000.

Sounds great, can you explain how this works?

From my understanding, it’s a “more accurate” version of tick(), or better said: a better version of it. If you need even more decimals you can use workspace:GetServerTimeNow().

No idea why they all give slightly different numbers unfortunately, but I assume they’re a replacement for tick() for the reasons given in the thread you linked.

3 Likes

workspace:GetServerTimeNow() and DateTime.now().UnixTimestampMillis / 1000 both sound great, thanks! I believe they return a different result than tick() because tick is based on your current timezone. Is there any way to adjust these values to my timezone? (Or whoever is playing’s timezone), if not that is fine, at least they return decimals and are similar to tick.

DateTime.now() supports changing timezones.

I’m not entirely sure how to do it since I’ve never done it before, but the documentation mentions it’s possible.

1 Like

Alright, I will try. Thank you!

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