Hello,
Recently made a game and had a bit of a datastore issue. To try resolve this issue I’ve attempted to transfer over to Datastore2, which worked well for about a day and then there were more reports of dataloss.
Additionally, there have been reports of them returning to the game with additional data (??), extra XP and levels. I assumed it was the loops continuing to run after they’ve left the game but I’ve just ran a few tests with a lot of prints and they do appear to stop.
I just need a second opinion to help me figure out whats going wrong. I’ve spoken to a few friends who are advanced programmers and they are also a bit stuck on what to suggest. I’m sure I’m missing something, so if you have any suggestions I’ll be extremely grateful to hear them.
LOADING DATA
local dataSheet = {}
local simpleDataSheet = {
["Galleons"] = 0,
["House"] = "Unsorted",
["Level"] = 1,
["XP"] = 0,
["WandMode"] = "RP",
["RPName"] = "NOT_SET",
["RPDesc"] = " ",
["EquippedWand"] = "Basic",
["EquippedBroom"] = "NONE",
["RPTitle"] = "",
["Detention"] = 0,
["XPBoosted"] = 0,
["GalleonBooster"] = 0,
["DailyReward"] = 0,
["DailyRewardBooster"] = 1,
["OwnedWands"] = {"Basic"},
["OwnedBrooms"] = {},
["OwnedSpells"] = {},
["Titles"] = {},
}
local function LoadData(player, DefaultData)
local DataStore = DataStore2(DataStoreName, player)
local Data = DataStore:Get(DefaultData)
return Data
end
function LoadSheet(keyName,blankSheet,masterSheet)
--\/--SIMPLE DATA
local loadedData
local success, err = pcall(function()
loadedData = mainStorage:GetAsync(keyName..player.userId) or blankSheet
-- the original datastore was losing data, so I just tried to salvage as much data per user as I could by obtaining their last save on the previous system, and using that as a 'default' table to pass.
end)
if err then
loadedData = blankSheet
else
dataLoadedSuccessfully = true
end
local toreturn = LoadData(player,loadedData)
--\/--FILLIN IN NEW VALUE
for key,value in pairs(blankSheet) do
if not toreturn[key] then
toreturn[key] = value
end
end
return toreturn
end
SAVING DATA
function saveAllData(leaving)
local DataStore = DataStore2(DataStoreName, player)
DataStore:Set(dataSheet)
DataStore:Save()
print("saving: "..tostring(leaving))
if leaving == true then
timeToEnd = true -- end loops for regular xp rewards
end
return "SAVE COMPLETE"
end
ADDITIONAL INFO
-XP is rewarded every 10 mins, I call saveAllData()
then as a precautionary save.
-Every dev-product purchase for money triggers a save too, just to be safe.
-When a player leaves, I call saveAllData()
-BindToClose is has also been set up.
-Not had a report of data being entirely lost. Just a few levels, spells, bought items or money missing. No one has experienced a back-to-default loss.
Any advice on how to locate any errors I may be missing or how to improve this code would be extremely appreciated. If you need anymore context surrounding code I’ll provide!
Thanks!