How to save and sync world data between servers

As some of you know, most of the multiplayer games’ server scripts are handled in websites, to perform sanity checking and updates game / world data.

I wanted a script that handles every server to send / get data.

This is a good idea for a game of MMO like single player servers, where each player is alone in each servers but able to communicate and connect with the other players.




Okay, but what about Messaging Service?

Scenario 1:
Imagine a voxel game, where you break / place blocks, if a player places a block for example, then it would send a message through all servers so that every server see the block you placed.

If a new player joins a different server, that player wouldn’t be able to see the block placed because the player joins a server before the Messaging Service event got fired.

We can just save the block placed data to the Datastore right, and load it when someone joins?

Well what if there’s several people that places / breaking blocks in different servers, how would it save them to the Datastore so that new players can see the block data on the other servers when they join?

Saving the world data first needed to have a cache of the world data, then save the data.
The problem here is that most scripts save Datastore slower or faster, so it may end up replacing most of the world data.

Remember that were saving the world data per each server script instead of one single script that handles every server.

If only I could use a single script that temporary store the world data and save them in array, so that when a new players joins a different server, I can use Messaging Service to get the world data and load it

This will save a lot of time and less expensive and less confusing to work with.




I apologies for the confusing the topic, and thank you for your time.

1 Like

Maybe you could update (Get and Set) the data when a new player joins a server and send a message with messaging service when someone modify something.

Yes but the blocks data including the modified one also need to be saved so that the new players can see the blocks

can’t you just place the block on the server?

Yes, but the game type I wanted is to have single players only per each server, so when one of the Player’s world is offline, people can still enter that world and modify anything. Also for making infinite it players.

This is possible to do my using the master transaction. It’s a well proven method to do this. You don’t need a core script that handles all the server.

A master file would hold the states of the entire game every hour or so. Then when a player makes an edit to a world that is sent to the transaction file and saved.

When a new player joins a different server the master file is loaded by default and the transaction is loaded on top of that after the master is loaded.

Doing it this way will allow you to do 2 things:

  • Lessen the load on access/changing of the master db. This can be done after a couple of days depending on how big you want your transaction file to get.
  • Allows you to ensure with 100% accuracy between data within each server. Master file is updated after the player leaves or when player count is low.

The transaction file will be applied to the database if it reaches a certain size. Any conflict that now appear will be resolved here.

Depending on how much data you need to store this may take up a large amount of storage on any database.

If you still insist on having a “centralised” script you can do that and communicate using HTTP but you need to setup hosting and the communication yourself.

Thanks for the response, that actually helped me!

I encountered a problem while reading that reply, The world’s data is compressed because its storing thousand of blocks.

If I were to modify something in the blocks, it will send a message to the server and what it would do is decompress the master file, edit the blocks data, compress the master file again.
It would be slow right? and the fact it keeps decompressing and compressing at same time might cause corruptions.

The idea with a master transaction file system is that you don’t do that.

The transaction file includes the changes to the database but you do not change the database every time it is accessed only when it gets to a certain point where the transaction file is too big to be stored.

This usually would take place once every couple of days.

The original world data will be kept whilst the transaction files are updated. To apply the transaction file all you have to do is go through every transaction and apply it into the database.

Any invalid transaction are dropped at this stage ensuring that you can keep your data integrity.

I will provide an example

Initial master file:

X 1 2 3 4
1 0 0 0 0
2 0 0 0 0
3 0 0 0 0

Here is a “flat” world where players can edit and change data. This can be compressed.
A player joins the game and the game is uncompressed for the player which sees this world and makes 3 edits

ID Value Column Row
1 3 1 1
2 3 1 2
3 3 1 3

Then another player joins and makes a couple more edits.

ID Value Column Row
1 3 1 1
2 3 1 2
3 3 1 3
4 8 3 3
5 4 2 3
6 4 3 2
7 2 4 3
8 1 1 3

The transaction file is pretty long now so we will go through each of the transactions

Note: we will only need to uncompress and compress once for all of these records. This makes it a lot faster.

X 1 2 3 4
1 3 0 4 0
2 3 4 0 0
3 1 0 8 2

Now our transaction file is cleared and our master file looks like this.

1 Like

Ah that make lot’s of sense, but where would I put the master file?

The server is only one player each, and the players in other server should see the world data same for everyone.
It saves when someone modify something so that every server will see the modified data. The only thing I could think of to accomplish this is using Datastore.

How would a master file handle this issue?

Okay I got it, when a player joins in someone’s world, they will be teleported in that place. In this way I don’t have to use MessagingService to communicate between player movements and blocks data modifications in a single server.

Yes, I am really stupid for not finding this out.

Though, thanks for giving some other workarounds, I learned some things from it and may use it in the future!

1 Like