Well, recently I have been learning about how DS2 saves data. I personally never really used DS2 for any games, because I just don’t like the way DS2 makes you “think” you’re making a new datastore and having variables for every content you put in.
Anyways, because of that I ended up making DS+, which works similarly. Except it has a MAIN version, DS2 only works on versioning. Meaning that it just gets the most recent indicator for a version and uses that to get data. The main version for DS2 is technically the newest backup. There have been some problems with DS2 in the past, like this. They’re mostly roblox’s fault. But, for example, the good thing about having a main version is that roblox can roll it back easily for you, without much thinking. There are problems with dealing with a main version, but those can be usually overcome with some changes in your system.
So, why does DS2 call it “OrderedBackups”? Well, it keeps indicators, as in “versions”, the most recent might be 100, 143, and it just finds the new one and stuff. A example of how that would work would be this:
local DataStore = DSS:GetDataStore("PlayerData/18472515") local orderedDs = DSS:GetOrderedDataStore("PlayerData/18472515")
These would be the datastores which are needed to get data.
The way data would be saved would be something like this.
Let’s say you wanted to save data, you would save a indicator pointing to a datastore value. So you might have the key to the new data as os.time() or in general, a higher number than the most recent version, it depends on your system of course. Berezaa says he uses os.time(), DS2 uses versions. As in comparing the highest value.
So your key might be “100”, or a os.time() value.
And the indicator to the ordered data store would be similar, having that uniquely always higher number, as it’s value.
An example of a code which puts this idea to mind, pretending we keep the version we got, would be:
local function Save(data, currentVersion) local orderedDs = DSS:GetOrderedDataStore(player.UserId.."/PlayerData") local dataStore = DSS:GetDataStore(player.UserId.."/PlayerData") dataStore:SetAsync(tostring(currentVersion + 1), data) orderedDs:SetAsync(tostring(currentVersion + 1), currentVersion + 1) end
I won’t be doing pcall examples, but you should be retrying and doing pcalls.
One example also for getting data:
local function Get() local orderedDs = DSS:GetOrderedDataStore(player.UserId.."/PlayerData) local dataStore = DSS:GetDataStore(player.UserId.."/PlayerData") local ordered = orderedDs:GetSortedAsync(false, 1) local page = ordered:GetCurrentPage() local data local isBackup = false local tries = 0 local versionGotten repeat for version, info in ipairs(page) do local getData = dataStore:GetAsync(info.value) if getData ~= nil then data = getData versionGotten = info.value else isBackup = true end tries += 1 end if data ~= nil or tries>= 4 or ordered.IsFinished then break end ordered:AdvanceToNextPageAsync() page = ordered:GetCurrentPage() until data or tries >= 4 return data, versionGotten, isBackup end
Reminder: I’m not doing pcalls here but you should.
Also, I do recommend having a main version, it helps like I said.
Anyways I hope that was helpful to anyone, just a reminder, roblox might send you some warnings about deleting certain player’s data, if they do, you have to remove every entry from the ordered data store and it’s correspondent data.
You can also have an clean up for older versions. Some people suffer with DS2 backups because they stay… Well, forever. So cleaning let’s say, versions older than 30 can be a good idea.