Best way to create a 'last online' feature?

I’m currently creating my own ‘friends’ system for a multi-place game. One of the features is a TextLabel which displays when a player was ‘last seen’, if they are not in-game.

To do this, every 60 seconds, the server retrieves a dictionary of all players to have ever played the game, which has a corresponding os.time() of when they were last online. If a player is in-game, it will update this time with the current time, then save the data. It looks like this:


Now, when there is only one or two servers for the game, this works really nicely. However, when more servers start popping up, correct me if I’m wrong, but this will increase the likelihood of servers calling the :UpdateAsync() with the same key, both at the same time, then resulting in the datastores throttling:

I could increase this waiting period from 60 seconds to a higher number, but as soon as I do that, the information on when the player last played starts to become inaccurate:

Also, increasing the time may work temporarily, but if the number of servers kept increasing, it would still continue to throttle the datastores.

So in summary, is there anyway I can modify my current method to prevent it from ever or rarely throttling, despite the number of servers, or should I create a whole new system for this, and if so, how would this be achieved?

1 Like

I would set the value to Online when they join the game, and then set it as Offline and tick() when they leave the game.

When a player joins the game you need to figure out a way to get their friend times without using all your requests. (If they have 200 friends and you try to get it for each one of them then you will use up over three minutes of requests immediately.)

If you have the time that they left then you can continuously update the times in the UI without checking the datastore every time.
You can connect an OnUpdate to each datastore which updates the value if they rejoin.

1 Like

This will eventually fail because the dictionary will be too big for a single data store key and you won’t be able to read/write to it from so many servers at once.

This looks correct to me. This solution doesn’t scale up to many servers.

Do you really need within-2-minute accuracy anyway? It doesn’t matter much anyway though, as this system will eventually break even with 120 seconds as your update time.

You should probably do this, yeah.

I don’t think you’ll be able to come up with a simple solution unless you use HttpService. I’m not sure if a good solution to this problem using Data Stores is even possible.

Your problem is very similar to the problem from this post: you need to get data for everyone in a large friends list without hitting data store limits. Your situation is even worse than that post’s though: you have to store and retrieve data for each user, and you have to do it very often. None of the solutions I discuss there will work well for your situation because you have to update data in so many places so often.

You aren’t going to get a good solution for this out of Data Stores.

Your best bet is using HttpService or scrapping the feature. If you go the HttpService route, then make sure that your game can work if your webserver starts erroring and expect to have to pay money for your webserver if your game gets popular.

One alternative, if you throw out “Last online”, is to replace it with just “Online” and “Offline” using GetPlayerPlaceInstanceAsync.


I understand this feature isn’t essential, however it would certainly help to enhance the friends system. Other games, such as Meep City, have achieved this, so there must be a practical way of doing this.

In terms of using httpservice, I ideally want to avoid this as I have very little ability in using it, and it’s mostly not worth paying money for a feature such as this.

I haven’t played Meep City much. My guess is that they run an external server for this. Their popularity and related profits would certainly be able to pay for one.

Perhaps you should keep it Online/Offline only for now using GetPlayerPlaceInstanceAsync, then update it to show last online time using HttpService if your game gets popular.


That might be worth a call.

If I was to set up a server using HttpService, where would be the best place to start learning how to do this, and what sort of costs would I roughly be looking at per month?

There are a lot of languages you can write webservers in, and one of the most popular ones is JavaScript using Node.js.

It’s been too long since I’ve learned it to know what resources are good for learning, so you can do a Google search for a start. Check out this Stack Overflow question that has tons of links.

I don’t know. I specifically avoid making features that require external servers as I don’t have the money to pay for them and don’t want my game to depend on them. I’d look it up, but I don’t have any good estimate of how much resources it would use, either.

1 Like

Ok thanks - I’ll begin searching for a way to do this after my other systems are in place. For the next few hours, I’ll keep this thread marked as unsolved to see if anyone else finds another solution, otherwise I’ll mark yours as the solution.