OS Time Sync Across All Servers

Is os.time() always in sync across servers?

I’m doing a weekly leaderboard system and I need to make sure…

1 Like

When called on the server it should always return around the same time, but I’m not sure if it may be off by a second or so.

I believe @berezaa said he had an issue where os.time() was off by nearly 5 minutes between different servers

1 Like

There were reports of os.time() being inaccurate up to around 10 minutes, although rarely. anything measured in hours or days is perfectly fine.

1 Like

Could you compensate for this by using http to get the actual time from a time server, finding the time difference and accounting for it when you need to get the time? This is assuming the time difference is constant between calls to os.time in the same server

1 Like

See:

When it works properly, ideally it should only ever be off by seconds between any two game servers, but if the bug above is still in swing then that might not always be the case right now.

When in doubt, you could always pick some publicly available time server and do an HTTP request there to fetch UTC time, then you can offset the server’s timestamp with the error between the retrieved UTC time and os.time.

4 Likes

So, when MessagingService gets released, would it better to use that for a Weekly Leaderoard Award System kind of deal?

that wasnt my question

2 Likes

I have made a similar system for my daily leaderboard system. I tried looking at online APIs etc.
I would recommend tick() over os.time().

In case you (or readers) need any help with the datastore for the leaderboard itself, I used this code to determine the week/day:

Code

return (math.floor(tick()/3600/24)) --daily

return (math.floor(tick()/604800)) --weekly

Then I’d make a new sorted datastore with this number of the week/day in it to store scores. (And a similar one to store the starting amount of each player per week, so the player starts at 0 every time.)

I feel like this would be better once universe scripts come out, then there could be one single script that manages a global leader board / prize system/ what not for all servers.

1 Like

That’s not coming out anymore. It got replaced with MessageService or something like that.

What’s messaging service about?

MessagingService is an upcoming service that will allow you to communicate with other servers in real time. Think of it like using OnUpdate for DataStores (which is bad and requires you to poll it every few seconds to get an “update”, so updates aren’t live), except much better.

You can use it to send out messages to other servers or receive them and act based on that. You can use this for things such as cross-server markets/trading, stat sharing and much more that involves communicating between servers. I’m not so sure if it’s also between places, but between servers I know.

I’d assume an announcement regarding MessagingService will come out really soon. The frontend is already enabled and you can already begin implementing it into your game, but the backend isn’t yet enabled (so it won’t do anything).

2 Likes

Wait, so where would this main script that communicates with all the other servers be?

Would it be in the game’s start place?

I dont understand, there should be only one script that utilizes this service right?

EDIT: So i’m assuming with this, you can better your existing leader board system by making sure every server is displaying the same info.

MessagingService can be utilised across any number of your places - figuring out how to utilise the service to your advantage is up to you. It doesn’t have to be in the start place, nor any connected places. Multiple scripts can use the service, not just one.

In terms of your leaderboard, I’d use MessagingService to prompt all servers to update their boards as opposed to sending leaderboard information to every server. Leaderboards are highly prone to updates and you might end up with a tangled mess of messages and subscriptions in your code. Even then, I’m slightly iffy on the usage of MessagingService (especially noting the latter point). It’s up to you to decide what should be sent to other servers live and what shouldn’t, as well as how you integrate everything into your game for a smooth experience and a working network.

It’s all about a matter of using services to your advantage and organising them in a way that’s comfortable, efficient and works well enough for your use case.

No, I don’t see how real-time messages between servers would help you set up a leaderboard, especially if it needs to know history too (not just new entries coming in). You’d still need to have a sorted database somewhere.

3 Likes

How can you make sure there is one global controller telling all the other servers to udpate though?

Or is that part of the Universe scripts that’s not coming?

You don’t. Every server would sport the same logic and based on the messages received or published, they’d toggle an internal state (local upvalue) to prevent overlapping or unintended updates.

In any case though, I did say that MessagingService is probably not the best plan for a leaderboard type system and was only speaking hypothetically from what I believed may be the intended work flow - I really just came here to explain what MessagingService was, lol.

You’d probably be better off sticking to having every server manage their own leaderboards via DataStore and polling for updates every so often in the background so as not to disrupt game play (i.e. if you update your leaderboards every 30 seconds, poll before the 30 second mark and send new data at the 30 second mark). I can’t imagine that the importance of synchronising leaderboards is heavy, nor something that is exactly manageable as of right now (given you do try and implement MessagingService, you may end up with a mangled network that you’ll get lost in).

Universe scripts probably would’ve been able to handle this since they run at the top-level, but I can imagine why it was delayed or cancelled. It’s not really possible and that would most likely cause serious overhead in games. If universe scripts were here, I’d imagine the workflow would look something like this:

  • UniverseScript contains an internal “intermission” - let’s say 30 seconds
  • Every 30 seconds, the UniverseScript would fetch poll the DataStore for new rankings
  • Once the data has been received, the UniverseScript would prompt every instance of every place via MessagingService that an update is to be made and send over the data
  • All subplaces or games utilising leaderboards would subscribe to the message and update their leaderboards with the received data
  • Rinse and repeat

Yeah the reason I’m so concerned with having everything in sync is because I have a weekly leaderboard and I want a random challenge every week.

The thing is, this is kind of impossible without the features of Universe scripts. And it doesn’t seem like MessagingService has any concern with making this work.

Can you send me a link to the Universal Script Update?

I don’t think there is a Roblox API page for it yet.