How would I make a countdown

Hi people! How would I go around making a countdown till a certain day. For eg. a gui that shows the amount of days till May 1st. I have never really understood how os.time/date so i dont really know how to do it.

3 Likes

I read a post on how to get time from google via HttpService. Given that google is a reliable service, I think it’s safe to say that you can rely your countdown from the time returned from google and subtract the date from the target date to see how much time is left.

2 Likes

PIL gives a great explanation on here:

https://www.lua.org/pil/22.1.html

if this is what you didn’t understand, what specifically don’t you get?

os.time() returns the current time in seconds from a certain date I don’t quite remember.

os.difftime() takes in two arguments which will return the range between the two. This can be used to create the timer system you were talking about.

I would think something like this, though I never tried it:

local trackingDay = 24 – 24th of this month
local dateTable = os.date(“*t”,os.time())
local daysLeft = trackingDay - dateTable.day

as Kurookku pointed out, try looking at the documentation for os.date for more information about the returned table. You could do a lot more with this if you wanted, like tracking the year and month.

@Thegameboy os.time(), tick() etc. are not accurate. Developers are complaining that servers are not in sync after a period of time.

The best solution is to get time from a single time server to avoid syncing issues as I have previously posted. There’s no need to deploy your own server, just use google as a web server using HttpService.

Time should be regularly updated to make sure the server still has the correct time. When servers are hit with lag, the time methods might desynchronise, hence the inaccuracies. If you were to use the script from the post above, regular Http requests must be made to get the most accurate time. I’m not experienced/familiar with the internal code for time, but anything math related on the server/client will pause if the instance is hit with serious lag.

2 Likes

um os.time is accurate… At most it might be off by a second but chances are those developers are doing something wrong with their code as i’ve never experienced an issue what so ever. Retrieving a time stamp from a third party requires http requests in which you’re limited to a small amount of to start with.

1 Like

How? The first thread literally shows the OP running print(os.time()) side-by-side in two different servers. There’s no way you can go wrong with printing the return value of a statement. Run this experiment yourself in a live production environment and come back with results.

500 requests per minute is not a small amount of requests and you barely will ever hit that unless you’re doing some kind of polling to simulate a near-real-time environment with your web server.

os.time works flawlessly, just because one server returns a different time doesn’t mean that they both run slower or faster than another.

That’s not the point though. os.time() returns the number of seconds since the UNIX Epoch, it has nothing to do with the speed of servers. It has to do with the number that’s being returned, which is fairly important if you’re looking for some form of synchronisation across servers.

If each server sports a different value off by enough figures to be noticeable, it doesn’t accomplish what you need adequately.

I don’t see an issue here as all the servers run off the exact same amount of seconds from the current time right now from a specific date back then.

Is there a possibility you can show me this issue right now?

First of all, we’re not saying the method you have provided is false or incorrect, we are just providing various ways for the OP to achieve what is being asked. As per our experience, even if os.time() starts the same on all servers, somewhere internally messes that system up and makes servers desynchronise their time. We cannot prove anything from an engineer’s perspective, but we can test our theories by doing what @colbert2677 has said.

Second, there is really no issue here, we have provided more than enough information to prove that os.time() is not synced on all server instances per game. If you really want to say that os.time() is accurate, well it sure is, but what we’re saying is it it does not stay accurate as time goes on. The function can return 5pm when called, but 10 hours later will return time behind 10 seconds more or less.

Third, we’re providing solutions to get the most accurate time because other games that rely on os.time() have experienced serious issues with this desynchronised time. We’re just looking out for each other, it’s all a learning experience.

3 Likes

Read the threads or create a repro test for yourself? They were linked for a reason and that was to show the discrepancy, as well as provide steps to repro the situation.

Servers aren’t returning the same amount of seconds since the UNIX Epoch. There’s a desynchronisation of nearly a full minute (linked threads).

1 Like