How do I get a list of all friends in-game, offline and online, who have played my game?

So I want to get a list of all friends in-game, offline and online, who have played my game at one point.

So my approach is when the player loads, I call GetFriendsOnline() and iterate all the UserIds with DataStore GetAsync() and check if a profile exists. But with 200 friends max, this will clog up the DataStore reserves. I also want a player’s Last Played date, which is in the GetAsync() profile.

What is some efficient way to make this?

3 Likes

Try using HTTP set for this. Creating a pastebin where all the user IDs get stored. This way you don’t have a clog on your datastore and it’s retrievable via an HTTP get string:match(id). Just keep track of the request limit for this

You aren’t really going to be able to get a hold of an efficient way to do this, since the available solutions for trying this are either data intensive or require third party intervention (HttpService). What are you using this data for? What’s your use case?

A friend’s list to identify which of your friend is on which server in a game, so you can join them if they are online.

You don’t need to track who’s played your game in the past before in this scenario. Doing so would introduce unnecessary work for your server, when all of this can be done on-platform. I believe this question has also been asked in the past but I didn’t run a quick search.

Instead of using GetFriendsOnline, use GetFriendsAsync. GetFriendsOnline returns you only online friends and probably provides you useless presence data that you most likely won’t read from. GetFriendsAsync will give you all of the user’s friends and their online status, which then you can sort them out into a list of some kind.

If you want to code in joining them or checking if they’re in a place of the game, use TeleportService.GetPlayerPlaceInstanceAsync to determine what instance a player is in if their presence state is online. This will give you an instance id which you can use with TeleportService.TeleportToPlaceInstance to directly join them. Automatic matchmaking should usually take care of this all for you though.

2 Likes

If I had to say anything? Don’t worry about finding out if they’ve played it or not.

Most game services that allow you to invite your friends don’t care if your friend already plays the game. It just says “Invite your friends!” and gives a list. It’s a good way to get new people into the game.

If you do that method there, you can skip the need to filter whether or not someone has played. If I had to recommend a method to determine if a friend is online, you could make use of the MessagingService which allows for relatively quick cross-server communication across your whole game (https://developer.roblox.com/en-us/articles/cross-server-messaging is a good resource).

Just send a request to the server saying “Hey is anyone in this list of players online in this server?” and have the other game servers respond accordingly. It should be relatively straightforward, but I have yet to invest time into the usage of this service.

1 Like