Hi, I own a popular game, and like the title says, I handled my datastore pretty poorly…
I have a separate datastore for each thing (coins, gametime, jail, etc…), which I have to use a get request every time a player joins for each one.
Example (some sample code directly from my game):
Coins = CoinsDataStore:GetAsync(Player.UserId) or 0
GameTime = TimeDataStore:GetAsync(Player.UserId) or 0
This obviously creates issues.
Instead of doing this, I want to fix this issue and set a single datastore where all this data is found, and I would only have to get it once every time a player joins.
I know how to do this, but because of the way I stored data (by userid), I’m unsure how I would convert everyone’s data into the new datastore while completely eliminating the need for the old one.
Is this not possible? Would I have to check for old data (if the new datastore doesn’t work), then save it to the new datastore? Or is there a simple one and done trick that I’m missing?
4 Likes
Yeah.
- Check if the new player has a new datastore already when they join
- If not, check if they have the old ones
- If they have an old one, move the data to a new one
Hide all this logic in some module, and save version numbers in your new datastore to make this kind of thing easier in the future 
2 Likes
I was afraid of this. More work for me, yay!!!
Thanks for the reply 
1 Like
Can you tell me what you mean by saving version numbers? What would be the purpose of this?
Like in your new datastore, you’ll have player data:
{
coins: 100,
deaths: 20,
items: {"diamond_sword", "wooden_shield"}
}
I’m saying that you should also include a special version field:
{
VERSION: 1, -- could also be a string like "1.0.0" or whatever you want
coins: 100,
deaths: 20,
items: {"diamond_sword", "wooden_shield"}
}
Then say in the future you decided that every item should also include a “condition” or something, so you want to change the structure to be:
{
VERSION: 2, -- we update the version
coins: 100,
deaths: 20,
items: {
{name: "diamond_sword", condition: 100},
{name: "wooden_shield", condition: 70}
}
Keep a bunch of modules whos only purpose is to upgrade a player’s save data from one version to the next (and no farther).
So for example say you’re on VERSION: 5 at some point in the future.
A player joins who’s on VERSION: 1.
So you run four data conversions:
- From v1 to v2, which tweaks the
items table to include conditions
- From v2 to v3, which adds a
pets list
- From v3 to v4, which reverts the first change and removes the
conditions from the items table
- From v4 to v5, which does something else
Then you save the new, updated data with VERSION: 5 for that player and they’re up to date.
1 Like