mirror of
https://github.com/msitarzewski/agency-agents.git
synced 2026-10-30 22:53:37 +08:00
fix(roblox): don't save defaults over data that failed to load
This commit is contained in:
@@ -100,6 +100,7 @@ local DataManager = {}
|
||||
|
||||
local playerDataStore = DataStoreService:GetDataStore("PlayerData_v1")
|
||||
local loadedData: {[number]: any} = {}
|
||||
local loadFailed: {[number]: boolean} = {}
|
||||
|
||||
local DEFAULT_DATA = {
|
||||
coins = 0,
|
||||
@@ -139,6 +140,7 @@ function DataManager.loadPlayerData(player: Player): ()
|
||||
else
|
||||
warn("[DataManager] Failed to load data for", player.Name, "- using defaults")
|
||||
loadedData[player.UserId] = deepCopy(DEFAULT_DATA)
|
||||
loadFailed[player.UserId] = true -- never save defaults over data we couldn't read
|
||||
end
|
||||
end
|
||||
|
||||
@@ -146,6 +148,11 @@ function DataManager.savePlayerData(player: Player): ()
|
||||
local key = "player_" .. player.UserId
|
||||
local data = loadedData[player.UserId]
|
||||
if not data then return end
|
||||
if loadFailed[player.UserId] then
|
||||
loadFailed[player.UserId] = nil
|
||||
loadedData[player.UserId] = nil
|
||||
return
|
||||
end
|
||||
|
||||
local success, err = retryAsync(function()
|
||||
playerDataStore:SetAsync(key, data)
|
||||
|
||||
Reference in New Issue
Block a user