Datastore Loss Data Help

Correct.

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.

1 Like

How can I fix it? is the fix same with @adamaniac suggestion?

Just combine all data into 1 table so you only have to setasync once or getasync once.

3 Likes

No you do not need remotes at all. You can use modules that are required serversided.

1 Like

As others have said above, I recommend condensing all of the values into a table to require less writing to stores.

I also recommend using UpdateAsync() over SetAsync() because you can consider the old data values for data loss traits before writing.

Do NOT do this, data management should never touch the client or exploiters can modify data to their hearts’ content.

1 Like

Ok then. I get it. I wont use remotes. Check my title. Yes, it says Animator not Programmer.

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.

1 Like

You can decide whether or not data gets forgotten with UpdateAsync(). I recommend reading this:

So you can either use the oldData parameter or you can forget about it, but UpdateAsync() has its uses either way.

2 Likes

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.

I also want to ask before anything else, does saving the stats in a table can be accessed and used in ordered datastore? I have global leaderboard.

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 ."

This whole process should be done under game.Players.PlayerAdded.

All you have to do is use DataStoreName:RemoveAsync(Key) for each of the 13 data stores.

How about when the player leaves the game? How can I save the stats from table in the new datastore?

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)
1 Like

No, don’t worry about it, I posted a reply in the wrong thread so I deleted it but it doesn’t get removed straight away - that’s what you saw.

1 Like

The player’s has left before the first data is saved meaning Player=nil.

I already did what they suggested above, saved the old datastore to a single data store using an empty table but how to prevent what you have said?

Store the player’s user id as a variable before you save

local userId = Player.UserId

Then use this variable instead of Player.UserId when saving.