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
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
