Os.time() returns different values for different users

My code uses os.time() to determine cool downs for quests. It works for most people, but for a select few my code returns the wrong time. I’ve now tracked the issue down to the fact that os.time() does not return the same value for each user.

My understanding is that it’s supposed to return the seconds under UTC time since a certain point in history, which should be universal and hence the same value for everyone. However this does not seem to be the case.
When I ran os.time() at the same time on my client, the server and the client of a user who has experienced these issues the result I got was:

  • The server time is equal to mine (as it should be)

  • The time returned for the other user was 1 hour off from the server time.

Any theories?

That’s not the case for the people that set the windows time to non automatic, they’d be 20 seconds or even more off (Happened with multiple people that I know)

@Exeriousless, the users must have their windows time set to automatic for this to work, else they’ll see some differences.

1 Like

I got it, thanks for informing me and warning me about the wrong answer.

Why use os.time? why not use os.date("!*t"), which returns a table of values of the current time

Either way, os.time will always return the value since the UNIX Epoch (00:00:00 1st January 1970 UTC)
The most likely reason the client’s time is off by an hour is because of DST not being calculated correctly.

I tested it using os.date(“!*t”) as well. It gave me the same result: They are 1 hour ahead and DST was false. Do you think the incorrect calculation is something the user can fix on their end?

Excuse my ignorance, and don’t know if this works but is this on the client or the server? Try it on the server?

The issue is a difference between the client and server, when there should be none.

The person in question was able to fix it by changing their timezone. This is interesting because it means os.time() and os.date() are indeed not fixed but instead dependant on the client. Will have to depend on the server more in the future when making these kind of systems.