I need an unique an synchronized time for all players in all servers.
Does os.time returns time from server or client clock?
os.time returns current epoch time. Which is the same for everyone. So it’ll return the same for the server and client.
Yes, but the question is: what hardware provides this time?
For example, my PC gives the time from its internal clock. Likewise, a cloud server can use the time provided by its own internal clock.
This way, if I have 100 servers doing this, I can have 100 different times.
Unless all servers get the time from a single clock/hardware, centrally.
So?
Depends if it is a local script or not. A local script will return the user’s current time, while a server script would return UTC +0
.
Edit: I’m not 100% sure, but thats how I understand os (roblox.com).
“os.time() - Returns how many seconds have passed since the Unix epoch (1 January 1970, 00:00:00), under current UTC time.”
This could mean that it either always uses UTC +0
or that each server uses it’s local time.
That’s the question!
Within my game, I need to make sure that all clocks are synchronized, regardless of which server the player is on, they must all provide EXACTLY the same time, as this will be used for important calculations.
If there is a time difference between the servers, it will cause problems in the game…
I would recommend you research unix epoch time.
This time is the same for everyone, no matter location or hardware.
honestly I really dont know
This google response seems to align with what the os.time()
states. Seems like the correct interpretation of
Is the former, it is always in UTC+0
:
Okay, since there is no absolute certainty, I created a test to confirm.
repeat
print(os.time())
task.wait(1)
until false
- I created the above script in a blank project
- I added a second user to TeamCreate
- I limited the project to 1 player per server
- I set up a Virtual Machine with the same Windows 10, but there FORCED A DIFFERENT CLOCK (1 hour before) to make sure that
os.time
doesn’t actually get the time from the client but from the server - I published the project and opened it on my PC and at the same time in the VM with a different user
… and the answer to my original question is:
The time is returned by SERVER and it’s always the SAME Unix Timestamp for all servers and all users, regardless of the user’s local time.