How to use DataStore2 - Data Store caching and data loss prevention

I have everything under one masterkey so there no problem with handling, but i figured out the problem!
It was because i made when data “TotalGold” and “TotalKills” are updating i also update with them OrderedDataStore to update my global leaderboards.

Heres how it looks like:

local DataStore = game:GetService("DataStoreService")
local TotalGold = DataStore:GetOrderedDataStore("TotalGoldGlobalLeaderboardDATAStore")

DataStore2("TotalGold", plr):OnUpdate(function(newPoints)
	TotalGold:SetAsync(plr.UserId, newPoints)
end)

Do you have any recommendations how could i update my leaberboard DataStore?
Like if i will make a loop that will update it every x minutes, but theres problem that if player leave it will not be saved and player will keep his old data, so i need to make also a thing that will save it also when player leave, but it can not save sometimes…

Update: I googled it and currently i save it every 2 minutes and on :AfterSave(). This works with no issues as of right now, later will do some tests with more players.

OrderedDataStores have a ridiculously low set threshold. This would be better placed in AfterSave.

hate to bother but i was hoping you could give your tought about this:

it tries to compare 2 diferent inventory modes (either a table or diferent datastores and then combine)

i have been playing with both but i dont want to shoot my self in the foot on the long run

1 Like

Personally, I suggest just using 1 table to store the data.

yes, but do i use combine to make it 1 big table or should i use a table directly

1 Like

Is there a way to save data using DataStore2 within a universe? Previously using DataStore, I could use the same name of the data store and have all my data save regardless of what place I’m in within the game, however I’m unaware of how to do this within a universe using DataStore2.

DataStore2 works normally with universes, it’s used in Zombie Strike and Dungeon Quest. There’s no special way of handling it.

1 Like

That’s epic! Thanks for creating this awesome module!

What do you mean? Sorry, I’m a bit confused.

Is there any tutorials out on the internet that explain how to create a global leaderboard using DS2? Dungeon Quest was able to accomplish this and I can do it with normal DS, but I can’t seem to figure out how to get it to work with DS2.

I’ve seen people attempt this and they say they have to get the OrderedDataStore, but there’s no API for this in DS2 so they find a workaround.

DataStore2 has no leaderboard support built in–you need to use OrderedDataStores directly.

So I’ve noticed that people have been losing data by quite a bit using DataStore2. The main trend between these people is that they attempt to play on multiple devices. So let’s say they are on phone, and then move to PC without closing off from phone, they would’ve lost all the progress they made on phone.

I’m not too sure, does anyone else have this? Or is it possible to change devices and keep data, and it’s just something wrong with my scripts?

Doesn’t roblox automatically kick the player on phone once joined on pc.

So what would this entail? Would this be my fault?

Edit so I found the source of the data loss:

I found that if players don’t close the current game window, and click play on the same game (causing the current game window to close); all the data they gained on that current game instance will be lost. Has anyone else experienced this? If so, what was the solution?

Maybe save the user data everytime it is updated?

Surely that would cause queues issue? Plus I thought the whole :Set functions deals with this?

What I do to avoid this is that I save the player’s data every 60 seconds to avoid data loss if the user were to suddenly disconnect.

1 Like

Wait can we have a look in your script? Maybe i know a possible problem.

1 Like

Can Datastore2 save bools? If so, how can we do it, I can’t find any mention about bool saving on the github.