'MessagingService' to replicate table?

Hello,
I am currently trying to experiment with something that might be out of my level but I still want to ask about it.

I am trying to make a table on a server script so that when someone buys/owns the gamepass or something like that, the user details/relevant details are added to this table and when this happens, the table is replicated to all active servers.

I think this should be done using the MessagingService? I am not that familiar with ‘MessagingService’ and never used it before.

Another question is : When you use ‘MessagingService’ , Do I still need to save the table or does ‘MessagingService’ do that?

1 Like

You could convert the table into a string with comma separators and parse it out on the other side.

1 Like

Hello! Thanks for replying.
Yes I know how to convert it to a string and what not but it’s more of how I would parse it out to the other servers if you know what I mean.

1 Like

If you separated each value with a comma, for example, you could go through each letter and every time it you found a comma you would add the previous letters to a table, remove those letters and the comma, and repeat

1 Like

Yes but how would I replicate it to the other servers?

You could have one big table on the server and add values to that from each time you use messaging service (assuming it’s not twice for one server)

1 Like

Hmm ok thank you! Would you by any chance know the answer to the other question please?

My suggestion would be using some kind of “sync” system. Personally here’s how I would go about this:

One server establishes that it’s the “leader” server (probably through DataStores) and when the table is updated other servers request the table to change (which is seen by all servers). When the leader server needs to send a change it can do that on the same key. Finally when a new server is created it gets established with the leader server and it’ll sync the table (through DataStore would be a good idea).

There’s one important thing: You’ll need the leader server to constantly be updating other servers so they know it’s online and using the BindToClose function make sure you sync when it gets shutdown as well. If it either times out or servers receive the close message they need to establish a leader.

In order to choose a leader you can pick alphabetically via the server’s JobId (whichever byte value is smallest will come first). Since the JobId is unique per server and they can all share the JobIds you know every server will come to the same conclusion without sending any special “I am the leader” messages which will prevent confusion.

1 Like

Thank you, Ill try this out later on!

1 Like

Now that I think about it switching from DataStores to MessagingService in both scenarios I mentioned would simplify the process haha. I hope that my solution helps!