In all of my games, I have a mechanism for saving/loading data that prevents data loss and overwriting with a simple check. It is a “DataLoaded” value. Here’s how it works.
Players.PlayerAdded:Connect(function(plr)
local DL = makeStat({Class = "BoolValue", Name = "DataLoaded", Parent = plr, Value = false})
local success, plrData = getData(playerKey) --[[ insert mechanism that checks
5 times in a pcall to retrieve the player's data and indicates if it's the player's
first time, and if there is no data when there should be, success returns false]]
if success then
-- load the data
DL.Value = true
elseif not success then
-- if the data wasn't found, you can kick the player telling them to rejoin or give the player a notification that data may not be saved.
end
end)
Players.PlayerRemoving(function(plr)
if plr.DataLoaded.Value == true then
-- save the data safely.
end
end)
It’s a very simple mechanism where data can only overwrite if the previous saved data is accurate to the player’s history in the game, and doesn’t completely reset it to the default stats. Can you see any problems with this? I have never gotten a data loss report ever - without having to use DataStore2 and other boilerplate complicated module methods.