This is a nice upgrade; however, still not the BEST for MY case. I understand how everything works and how we’re supposed to delete their data, okay I’m fine with that, but there’s not much (for me at least) to make the process less tiring. I could simple do normal datastores for my game, but I’m too iffy when it comes to datastores having the possibly to fail (obviously), and that’s why I use a different system for my game.
I use OrderedDataStore/DataStore for my game, so I can save multiple versions of the player’s data by creating a new key to the OrderedDataStore using os.time() - so technically, I’d have a copy of the player’s data every time they played the game - counting with the auto save that saves a copy of their data every 3-5 minutes. Now imagine, if I get a request to delete their data, what if they have over 500 saves of data? it would take a good while to erase all the saved keys on the OrderedDataStore AND removing all these saves in the main DataStore.
I had the idea of getting all the game’s datastores and filtering by the player’s id, but that would ALSO take ages since I use a datastore for each player…
local DATASTORE_KEY = "DATA:%d"
local DataStoreKey = DATASTORE_KEY:format(Player.UserId)
local DataStore = DataStoreService:GetDataStore(DataStoreKey)
local OrderedDataStore = DataStoreService:GetOrderedDataStore(DataStoreKey)
This is been the safest method of data saving that I’ve been using for ALL my games, given if any errors occurred I could simply force them to return to an old version of their data (which never happened).
This is how I save the data:
local Key = os.time()
DataStore:SetAsync(Key, Data)
OrderedDataStore:SetAsync(Key, Key)
And this is how I load the data:
local Default = GetDefaultData()
local Data = {}
local MostRecentKeyPage = Retry(function()
return OrderedDataStore:GetSortedAsync(false, 1):GetCurrentPage()[1]
end).Data
if MostRecentKeyPage then
local Request = Retry(function()
return DataStore:GetAsync(MostRecentKeyPage.value)
end)
if Request.Success then
Data = Request.Data
else
local Message = "Error while loading %s's data! Error: %s"
Message = Message:format(Player.Name, tostring(Request.Error))
Debug(true, Message)
if Player and Player.Parent then
Player:Kick("Couldn't load your data! Please rejoin.")
end
return
end
else
Data = Default
end