My idea is to have a function that checks if their data has all the keys that are in the default data, I coded this so you know what I mean:
function GetDefaultData()
return {["Coins"] = 0, ["Wins"] = 0,["Gems"] = 0}
end
function Check(SavedData)
local DefaultData = GetDefaultData()
if #SavedData == #DefaultData then
return SavedData
else
for Name, Value in next, DefaultData do
if not SavedData[Name] then
SavedData[Name] = Value
end
end
return SavedData
end
end
and when you’re getting their data from the data store you can use something like this:
local SavedData
local Success, ErrorMessage = pcall(function()
SavedData = SavingDataStore:GetAsync(PlayerKey)
end)
if Success then
local CheckedData = Check(SavedData)
return CheckedData
else
warn(ErrorMessage)
local NewData = GetDefaultData()
return NewData
end