rarely, when I try to save data to datastore HTTP-smth error appears and doesnt save the data
How do I counter this and save the data anyway, its gonna be annoying if thats happens to a player and they lose their data from this session
theres code: (very basic)
local DataStoreService = game:GetService("DataStoreService")
local UpgradesSave = DataStoreService:GetDataStore("Upgrades")
local CurrencySave = DataStoreService:GetDataStore("Currency")
local function serializeUpgrades(folder)
local data = {}
for _, item in folder:GetChildren() do
data[item.Name] = item.Value
end
return data
end
game:BindToClose(function()
local ownerId = game.ReplicatedStorage.PSOwnerID.Value
if ownerId ~= 0 and game.ReplicatedStorage.DataLoaded.Value then
pcall(function()
local upgradesData = serializeUpgrades(game.ReplicatedStorage.Upgrades)
UpgradesSave:SetAsync(ownerId, upgradesData)
end)
pcall(function()
local currenciesData = serializeUpgrades(game.ReplicatedStorage.Currencies)
CurrencySave:SetAsync(ownerId, currenciesData)
end)
end
end)