Hello, I’m currently making a game where the player is able to add their friends into an in-game friend-list, each player has a total of 10 in-game friend-list slots stored in their datastores which are loaded and saved in the current server they are in. The way this works is when a player adds someone to their in-game friend-list, they BOTH take up a space in both of their in-game friend-list slots. Ex. Player A’s slot 1 being filled with Player B, and Player B’s slot 1 being filled with Player A.
When a player wants to unfriend someone (For example Player A wants to unadd Player B, the game will set the slot that Player B took up in Player A’s data and set it to “Nobody.” While doing so Player B will also have Player A set to nobody.) (That way if one of the player’s is offline, the game is still able to update BOTH of the player’s data.)
However the problem lies when Player A and Player B are both in different servers. As when Player A tries to unfriend player B, Player B’s data will be updated, however it’s local data inside of the current server Player B is in will not change. Thus causing Player B’s local data to overwrite the new updated data from Player A. Which causes Player A to have Player B removed from their in-game friend-list, however Player B still having Player A added.
How would I go about updating both player’s data’s accurately without causing any weird issues between the two?
The Problem: When Player A unfriends Player B in a different server, Player B’s local data doesn’t update so it overwrites the datastore when they leave causing desync.
You can Use Robloxs MessagingService to send a message to all servers when a friendship changes. The server Player B is in receives the message and immediately updates their local data before they can save and overwrite it. You can also add timestamps to each friend slot so older data never overwrites newer data when saving.
4 Likes
How fast is MessagingService? Does it have a delay?
yeah this is one of those tricky things with datastores across multiple servers — if both players are online in different places, their data basically becomes “unsynced” and whoever leaves last ends up saving over the changes.
what you’re running into is called a race condition, and the best way around it is to not trust the client’s memory for live datastore values, especially when it’s shared across players.
some ideas that might help:
- when Player A unfriends Player B, go ahead and update both of their datastores immediately on the server, like you’re doing
- then, for Player B — instead of waiting until they leave to save, you could force a refresh from the datastore every X seconds, or right before any save, to make sure you’re not overwriting changes
- OR, better: set up a MessagingService event. when A unfriends B, you publish a message that B’s server listens for, and updates their local version without needing a full refresh
that way both sides stay in sync even if they’re on different servers
1 Like