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

Random rejection

  • It does save in-game but sometimes it rejects, which results in non-saving data

Datastore2 seems not maintained anymore, i’m currently too busy to switch to ProfileService
Does anyone know a fix for this error? (DataStore2 > SavingMethods > OrderedBackups)

Edit:

Edited the Standard saving method to retry :point_down: whenever 403 (Forbidden) occurs

self.dataStore:UpdateAsync(self.userId, function()
	return value
end)
Updated Code

Make sure to use the latest Promise release if you use this edit

-- Standard saving of data stores
-- The key you provide to DataStore2 is the name of the store with GetDataStore
-- GetAsync/UpdateAsync are then called based on the user ID
local DataStoreServiceRetriever = require(script.Parent.Parent.DataStoreServiceRetriever)
local Promise = require(script.Parent.Parent.Promise)

local Standard = {}
Standard.__index = Standard

function Standard:Get()
	return Promise.async(function(resolve)
		resolve(self.dataStore:GetAsync(self.userId))
	end)
end

local function updateAsyncRequest(self, value)
	return Promise.new(function(resolve, reject)
		local success, result = pcall(function()
			self.dataStore:UpdateAsync(self.userId, function()
				return value
			end)
		end)

		if (success) then return resolve(result) end
		reject(false)
	end)
end

function Standard:Set(value)
	return Promise.retryWithDelay(updateAsyncRequest, 5, 1, self, value)
end

function Standard.new(dataStore2)
	return setmetatable({
		dataStore = DataStoreServiceRetriever.Get():GetDataStore(dataStore2.Name),
		userId = dataStore2.UserId,
	}, Standard)
end

return Standard

You can literally watch a tutorial on ProfileService that explains it great. One such tutorial is from VectorThree.

i have but i dont use it because i dont understand it even after watching tutorials plus i’d rather make it myself so if i want to add anything i can know where to start

This just looks like a Roblox outage to me.

3 Likes

Yes I know. I wasn’t specific enough. I meant like, isn’t there a way to prevent this from happening, as in retrying to call the function?

I wouldn’t recommend it. Just use the DataStore from Roblox. What I do is I create a module script where, if a player joins, their data will be stored in a table. If they don’t have existing data, new data will be created. I store everything in this table, and when the player leaves, it gets saved.

Suphi’s Datastore Module is the best option rn imo.

Well, it has its downsides. I’d still prefer to use ProfileService over Suphi’s Datastore Module.

Thank you so much for creating this, I’m gonna use it for my little game named normal day.
I hope there won’t be any data losess like they happened (4 times they happened and they were pretty big)
if anyone interested what the data losses was so here u go: first and second data loss was the serial keys they were lost 2 times (idk why to this day) the third data loss was the players money and the fourth data loss was companies budget (basically 170k money reset thats alot tho i backed it up to somewhat around this value)

These two already explain by DataStore2 should not really be used anymore. You should either use the default Roblox Datastores with their new API and all that stuff or you can use ProfileService which I have given a link to a great video explaining how to use it above.

Edit: Roblox Datastores do provide versioning! (ProfileService does too)

why do i get this warn?

Since the points value was not changed/updated, DataStore2 did not save the value.
Edit: Sorry for bumping.

Hey,

is there a Community Ressource for DataStore 2 on Discord or on any other Social Media? If so can you send me the link so I can discuss with someone because I have a lot of question for that

Hey so how do i get the current value of the datastore? Do i just do something like:

local stat = game.Players.bbackstab.leaderstats.Stat.Value