Update data without overriding data in other servers

I am creating a “crew” system. Players can join and leave a crew and crew leaders can change settings, kick members, ban members and accept join requests all within the game. Data is saved locally in the server in ReplicatedStorage for each crew that’s in the game. When a player joins the game while in a crew with no other players in the same crew or someone joins a crew when there are no others in the same crew in the server a folder is created for that crew with all the data. When the last player in a crew leaves the server the data is saved to the Datastores. I have done this to cut down on load times and to limit the amount of DataStore requests. If an owner of a crew or another member wants the data to update in other servers they can click an “update” button to save the data and players in other servers can click a button to load that data into that server.

However, I’ve run into a problem: How do I update data without overriding other servers’ data. Any help would be appreciated.

1 Like

@loleris created a helpful DataStore module called ProfileService, and he lists session-locking as one of it’s features.

I have yet to try it out myself but it looks like it might help solve some of the issues you described; for example you could set up a profile for each ‘crew’ so that it updates in the background, and have it save when the last member exits.

2 Likes

I don’t know what your code looks like but I think the way you are handling this is wrong. Are you saving all the crews over the same key so it ends up only holding one server’s crews? You would have to process and append new data to the current data in order to use the same key.

But don’t do that. Instead create a store for the crews and store each crew under its own key. Put all your crew data here including the member list. Have a separate store for player data and save the crew that they are in to make it easy to set up when joining the game.

Also, you shouldn’t wait until all players leave to save data. If you want two servers to be able to have the same crew active, you cant. You should create a queue system to post updates at a controlled rate. Every time a change to the local data is made, queue it to be updated. The request limit is real time and you don’t need to worry about it this way. There is no problem with consistently updating a store.

I am saving each crew’s data as a dictionary under its own datastore key. This is separate to the rest of the player data.

I don’t understand how you are overwriting this way. Is it when the same crew is active on two servers and they alter and upload from their local data and never receive updates?

If the local data from the server is saved, the newest version that is already saved would be overwritten by the local data because it does not update the local data when data from another server is saved to the datastore.

If you use updateAsync you will receive the updated data from the store as an input and you can compare that data with the server to not overwrite. Only write the parts that were changed instead of throwing the whole chunk in. I suggest creating a update queue system for this. You can also use community made data store modules that will handle all this for you.

You could periodically read the store and update each server so users know of changes made in other servers but don’t rely on that to fix this problem because it will still happen if caught between updates.

1 Like

I have never used UpdateAsync before but from what I’ve read it requires a function to compare the OldValue and the NewValue. I cannot think of a way to compare both values as they can differ a lot. The data being saved will be stuff like settings, ban lists, join requests, member lists and audit logs. I can understand how it can be used for the audit log but not for the others.

A simple way to do it is keep track of what specific values from the table you want to change and apply those only in the update function.

1 Like

I’m still a bit confused because if you’re just updating the data that was changed in the server isn’t that the same as just saving the local data?

You have a set of data that is now completely out of date to the data store. You click a button to ban someone and update the data store. You receive the up to data data and add the change which is the banned user.

You cant directly update the store every time a change is made if they are made too quickly. That is why you should queue changes. Make another table that you save changes to as you alter the local cache. Use that table to apply all the changes when it is appropriate to send an update request.

2 Likes

I dont rly get it. Where would you make that queue Table? How would you you use that queue table exactly? Im a bit confused still.

Im doing the same thing. Im making a crew system where players of a certain rank can kick people and that update of the person’s removal is spreaded throughout all of the servers. I also want this to work in different servers as well as the same server.

But like you said , if too many people update the same data with the same key to many times , it could break the data store!

Can you go into depth about how the Queue system will work?

how do you queue it???
I really want to know.