MessagingService or Datastore or both?

Hello,

I am currently planning something out for my game. My game is basically about opening packs and collecting cards/items etcetc. What I have in mind is creating a section where users can buy a gamepass to have a card of themselves in the game and makes the card able to be found in packs along with other cards.

What I was thinking was : I create a table on the server which stores all user and relevant details once the gamepass has been bought. Now what I want to do is replicate the user and relevant details added in the same table on all the other servers, so that the card will be available on all active servers. I also want the table to be saved with all users who bought/own the gamepass.

Questions :

  • Do I have to use both MessagingService and Datastores to do this?
  • Can you please go through the process briefly to be able to do this?
2 Likes

If you plan on having the Player’s cards saved forever throughout all servers you would want to use datastores. You could have a datastore save “CustomCards” or something like that. Then use MessagingService to communicate to every server that a Player has bought a custom card. Now update the datastore to have the custom card received via messagingservice.

When the server receives the Custom Card’s data you can do whatever you want with it now. You can add it to the server’s card shop. Then when a player buys it just make sure you save the card like any other card in their deck.

One problem with this method is if too many Player’s purchase a custom card then every player will have a datastore filled with custom cards. I believe this would cause some problems but I am not 100% sure.

Another method would be to only add the custom card if the Player who owns the gamepass is online. For this you could check if the Player owns the gamepass when they connect. Then use messagingservice to tell every server that their is a new custom card. Player’s can buy it and keep it and do whatever with it. Then when the Player who owns the gamepass leaves their game you can use messagingservice to take the custom card out of the server.

There may be better methods, but these are just what I thought of.

1 Like

The second method is definitely not suitable as I would want the card to stay there even after he leaves.

And about the problem for the first solution, can’t you just save the datastore on the server using IncrementASync?

1 Like

Yes you can. I actually just discovered that right after writing that post and researching.

Actually, someone told me IncrementASync only works with numbers, Im not entirely sure tho. What I have to do is just create a unique Key for the datastore without a player’s userid.

1 Like

You can use OrderedDatastores for this. They have stricter budgets but for your purposes would work much better since they would allow you to store keyed data and loop through it later. You can store their UserId this way.

1 Like

Never used them but I will do some research about them. Thanks dude.

Awesome! One thing I missed was they can only hold number values since they’re primarily intended for sorted data like scores (and same standard with keys, only string keys)

1 Like