I should point out that if you now condense those 13 datastores into a single one, all of your players data would be wiped. Either you have to live with that or maybe run a transition period for week or two where if a player joins and they have data stored in the old datastores it grabs all the data from it, saves it in the new one and removes their data from the all the old datastores.
Note: Doing this transition period comes with the same risks of data loss, like as @RatiusRat said it would be querying the datastores to many times.
The game has been running for months now so the data must be move to the new datastore but I have no idea on how I will grab the data from old datastore to save to new datastore, do you have any example so I can try to understand?
The issue with my game is that some of player’s data resets so by using UpdateAsync, will it prevent from getting the player’s data back to 0 instead it will only go back to the last saved data? for example, the player has 5 coins, but during the game it gets to 10 coins then he leaves the game or crashed the game. When he go back he will get 5 coins instead having 0 again? sorry for my bad english
Okay, essentially keep those datastores declared so they can be accessed, when a player joins create an empty table and run GetAsync on each datastore, if there is data for the player in those datastores, put the retrieved value in the table. Once that is done save that table to the new datastore and run RemoveAsync on each of those 13 datastores so it does not repeat this process again.
I suggest using some wait statements when getting and removing the data during the above process so that you do not reach the datastore limits quickly. It will slow the process but reduce the likelihood of failure.
Hello I still don’t understand well how to do what you suggested but I try this one which I feel I had many mistakes.
On top of the codes below the declaration of old datastore, I wrote this one
local player = game:GetService(“Players”)
local NewData = DataStoreService:GetDataStore(“NewData”)
–created empty table, im not sure if this should be global or inside the player added function
local data = {}
Inside the game players added function, I didn’t touch anything instead I just added this at the end of the function
if dataSpent then
Spent.Value = dataSpent
end
--this one
for _, stat in pairs(player.leaderstats:GetChildren())do
data[stat.Name] = stat.Value
end end)
Then on game players removing, I still didn’t touch anything but added this which I don’t know if correct
earnedCoinsStore:SetAsync(Player.UserId, Player.leaderstats2.Earned.Value)
spentCoinsStore:SetAsync(Player.UserId, Player.leaderstats2.Spent.Value)
--this one
for _, stat in pairs(player.leaderstats:GetChildren())do
NewData:SetAsync(Player.UserId,data[stat.Name].Value)
end end)
On the RemoveAsync, I have no idea how I will write it on my codes.
No, at least I don’t think it can. " A OrderedDataStore is essentially a GlobalDataStore with the exception that stored values must be positive integers ."
local data = {}
for _, stat in pairs(player.leaderstats:GetChildren())do
data[stat.Name] = stat.Value
end
local success, err = pcall(function()
dataStore:SetAsync(player.UserId, data)
end)