I have come across a weird thing.
But here a small look on the saving system:
local function Saving(Plr,eInfo)
local DataSave = {}
for _, v in ipairs(Plr.Stats:GetChildren()) do
DataSave[v.Name] = v.Value
end
DataSave.RedeemedCodes = RedeemedCodesCache[Plr.UserId] or {}
local dailyFolder = Plr:FindFirstChild("DailyQuests")
if dailyFolder then
DataSave.DailyProgress = {}
DataSave.DailyCompleted = {}
local progressFolder = dailyFolder:FindFirstChild("Progress")
local completedFolder = dailyFolder:FindFirstChild("Completed")
DataSave.DailyQuestList = {}
local progressFolder = dailyFolder:FindFirstChild("Progress")
if progressFolder then
for _, v in ipairs(progressFolder:GetChildren()) do
table.insert(DataSave.DailyQuestList, v.Name)
end
end
if progressFolder then
for _, v in ipairs(progressFolder:GetChildren()) do
DataSave.DailyProgress[v.Name] = v.Value
end
end
if completedFolder then
for _, v in ipairs(completedFolder:GetChildren()) do
DataSave.DailyCompleted[v.Name] = v.Value
end
end
DataSave.LastDailySeed = math.floor(os.time() / 86400)
end
local weeklyFolder = Plr:FindFirstChild("Weekly")
if weeklyFolder then
DataSave.WeeklyCompleted = {}
for _,v in pairs(weeklyFolder:GetChildren()) do
if v:IsA("BoolValue") then
DataSave.WeeklyCompleted[v.Name] = v.Value
end
end
DataSave.LastWeeklySeed = weeklyFolder.Seed.Value
end
DataSave.Achievements = {}
for _, achievement in ipairs(Achievements) do
-- print(achievement.Completed)
DataSave.Achievements[achievement.Id] = achievement.Completed
end
print("ABOUT TO SAVE", eInfo)
print(
"UpdateAsync budget:",
game:GetService("DataStoreService"):GetRequestBudgetForRequestType(
Enum.DataStoreRequestType.UpdateAsync
)
)
local success, err = pcall(function()
print("PCALL ~")
PowerDataStore:UpdateAsync(Plr.UserId, function(oldData)
print("Inside of the PowerDatastore")
-- oldData = oldData or {}
-- for k, v in pairs(DataSave) do
-- oldData[k] = v
-- end
return DataSave
end)
end)
print("PCALL FINISHED", success, err)
if not success then
warn("Failed to save data for", Plr.Name, err)
else
print("SUCCESsy")
end
end
local STOP = false
game.Players.PlayerRemoving:Connect(function(Plr)
if STOP == true then return end
Saving(Plr,"REMOVE")
end)
game:BindToClose(function()
STOP = true
for __, Plr in pairs(game.Players:GetPlayers()) do
--task.wait(2.5)
Saving(Plr,"CLOSETHEBINGIND")
end
task.wait(5)
end)
task.spawn(function()
while task.wait(350) do
--if STOP then break end
pcall(function()
for _, Plr in pairs(game.Players:GetPlayers()) do
--task.wait(2)
Saving(Plr)
end
end)
end
end)
Now the issue was that SOMETIMES, not always, it does not save. This would occur when only printing PCALL but not inside Powerdatastore or anything after, and even if it saved it would not print successy. Only after adding task.wait(6) in the bind to close function it printed these things and the content would be saved.
I have asked my local AI companion, which parents I highly dislike, and they gave me this as I asked them if it was possible if the player left before bindtoclose, if it could break. And it seems like that is somewhat the case, but there are some issues with this, like should bindtoclose not wait, so that all players leave and then run. which would make calling the function in the first place impossible (It is possible though). And flaw, flaw, flaw. Please explain I need a good answer.
