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

I don’t understand the question. Just use multiple stores.

Read the documentation.

Ok I fixed it, another question. Can I make leaderboards with datastore 2? Like getting an ordered data store? Thanks :smile:

No, this has been said multiple times for DataStore 2. Same with Profile Service. These aren’t made for OrderedDatastore. Just make a Instance value object and use that for Ordered Datastore.

1 Like

If I am updating a table (which I got from :GetTable()), should I update it by updating its values by using :Set(newTable) or is there another method (other than :Update()) that I should use?

Well the answer is no, I believe; She meant having for instance, Kills on both PlayerData and elsewhere for instance;

You really shouldn’t have more than one combined key.

1 Like

Btw, kind of was curious, have you ever considered rewriting datastore2?

I ask because people have been moving from DS2 to Profile Service and other modules;

Not really, there’s no point–I made DataStore2 to release games faster, not to write code.

1 Like

I thought the berezaa’ method was discouraged?

Also do you have anything explaining how Standard Method backups work?

Yes, but is still the default. Changing it would break basically every game that uses DataStore2.

Yes, the documentation should explain it. The specifics shouldn’t really matter to you, it’s all implementation details.

1 Like

Lol true, I am just like messing around with making my own module for using OrderedBackups because it basically allowed me to convert games into OrderedBackups with like 1 click. I think I understand how OrderedBackups work, but anyways, that’s why I asked lol

Is there a way to clear all keys more efficiently? I was requested to clear someone’s data who has been playing for weeks now, they have a total of 36k keys, it’s been about 5 hours now and they’re still on 14k keys. I’m worried that people will become vindictive and decide to request their data to be reset and they have thousands of keys.

If you’re using the default OrderedBackups method, then no.

1 Like

Is it possible to switch from ordered back ups to standard? Or will it reset everyone’s data.

It’ll reset the data, they’re completely different data structures.

1 Like

I’m having trouble modifying the script to get the player’s offline data. Would be helpful if you could update the module :slight_smile:.

Is there a limit to how many times you can use :Set() at a time?

I’ve used Datastore2 correctly, but for some reason data loss occurs often.

I did lots of research and even looked to hire people, and the only thing I could find was that using :Set() too much is bad.

I’m thinking of adding automatic cleaning in my orderedbackups module, but what you can do here is make your own system based around DS2 on which if data is older than, let’s say 10 versions, it gets deleted from the datastores and from orderedbackups listing.
I’m not sure why DS2 doesn’t have that…? Kind of crazy that there’s 32k keys just from versions. I don’t even think I could reach that with the amount of times I played some games.

From what I know, no it shouldn’t be. DS2 is supposed to be used in a way on which you change the data that was gotten from DataStores and then it saves when you leave the game. You might just not be updating the data? If you don’t, it doesn’t request anything, also SavingInStudio is usually a little spotty so could be that.

Kampfkarren as he said “My projects move with me.” And it seems like he’s not gonna update this in some time. Thankfully it shouldn’t be that hard to get the data.

DS2 saves a indicator of the version that was saved on OrderedDataStores. That is used to find actual data on an actual DataStore. The dataStoreName is based around the actual DataStore and it’s player key (on ds2).

Then there’s the actual DataStore that keeps the data with versions. Those never get deleted.

This should list the versions for you:

local mainkey = nil
local userId = nil

local dsService = game:GetService("DataStoreService")

local orderedDs = dsService:GetOrderedDataStore(mainkey.."/"..userId)

local ordered = orderedDs:GetSortedAsync(false, 10)
local page = ordered:GetCurrentPage()

repeat
    if ordered.IsFinished then
        print(page)
    else
        print(page)
        ordered:AdvanceToNextPageAsync()
        page = ordered:GetCurrentPage()
        print(page)
    end
until ordered.IsFinished

Now you can get a request by doing this:

local mainKey = nil
local userId = nil

local versionToGet = 1

local dsService = game:GetService("DataStoreService")

local ds = dsService:GetDataStore(mainkey.."/"..userId)

local data = ds:GetAsync(versionToGet)
print(data)

Of course just change the versionToGet to the most recent and highest rated version you find there.

Now since you wanna change data, you can do a Set / Update request to that key if you can read it, it shouldn’t be hard.

im so mad i had to retype this because I deleted the code I- omg.

2 Likes