How should I set a player's data from a different server?

I don’t know how I should approach this. This is necessary for my upcoming game, because people can ‘buy’ a product from other people, even when the seller is in a different server or offline. The way I’m storing my data right now is via ProfileService using session data to temporarily store player data. The problem is that I can’t change another player’s data if they are in a different server, lest it saves incorrectly or corrupts their save. I thought about using a different data store system, but session data systems are the most optimal for my game, yet it still causes this problem.

TLDR

I need to change another player’s data while they are in a different server (or offline), while maintaining my current data system that uses session data.

Please let me know what you think!

This might seem daunting at first, but really if you break it up, it seems more manageable.

  1. Figure out how to communicate between servers
  2. Save data such as that.

How to communicate between servers

ROBLOX has a neat little API which isn’t talked much, where you can talk between different servers. This is typically how games such as “Perris, California” have server lists where you can join.

This is called MessagingService

You would use MessagingService:PostAsync(topic, message) to post a message between all servers, and then create a function that listens for that message

local connection = MessagingService:SubscribeAsync(topic, function(message)
	print("Received message for ".. message.Data .." in topic: "..topic)
end) 

The topic can be anything. Imagine these are news articles which update whenever

The “Topic” is just the title of the news report.
The “Message” is what actually is within the news report.

Save the Data

The game would listen for a specific topic, e.g. playerBoughtAProduct
And then the message could be a table, which could look something like this

print(message.Data)
{
    ["Buyer"] = "ILoveBuyingPeopleThings",
    ["Recipient"] = "PeopleBuyThingsForMe",
    ["Product"] = "LazerGun"
}

Once the message is received, the server would first check whether the recipient is within the server.

If the player isn’t, then it is ignored, because the player isn’t in the server.
If the player is in the server, then give them the product.

To do the offline check, you could create a secondary topic, where only if the product is given, then send a message to the topic, could be called playerReceivedProduct.

This will be received by the original server (add like a wait time of around 5mins). If the original server (where the player actually bought the product for someone else) did not receive anything about playerReceivedProduct, then perhaps manually edit the recipients datastore with a new variable called giveOnJoin, and when the player joins, they automatically get it, and the datastore value is erased.

This might seem longwinded, but hopefully it works! If anyone has any other recommendations, just let me know.

1 Like