My game Find the Fridges has been dealing with strange save data issues that are causing a lot of people to lose data. I would like some help on how to fix/improve it.
One of the ways players lose data is whenever they leave, their data doesn’t save and the else statement in the pcall for if it errors is ignored for whatever reason. I don’t know why but this issue has had a surge in occurrences and is happening a lot more now for some reason despite me not updating the Datastore and it is causing my game to get a lot more dislikes.
The other way is a lot more uncommon but it is when they join their data doesn’t load and they lose all of their progress.
I have tried looking into DataStore2 and Profile Service but they won’t work well with my game as I have over 103 different pieces of data to save and it would take forever to change everything to work with them. I am looking for a way to make data errors a lot more rarer without having to completely change a ton of code in the game.
local DataStoreService = game:GetService("DataStoreService")
local Players, DataStoreService = game:GetService("Players"), game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
local RunService = game:GetService("RunService")
local function load(player: Player)
local playerUserId = "Player_"..player.UserId
local data = nil
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
player:WaitForChild("ValueFolder").Moneys.Value = data.Moneys
player:WaitForChild("leaderstats").Fridges.Value = data.Fridges
player:WaitForChild("FridgeFolder").BasicFridge.Value = data.Basic
else
print("Save Error")
warn(errormessage)
end
end
local function save(player: Player)
local playerUserId = "Player_"..player.UserId
local data = {
Moneys = player:WaitForChild("ValueFolder").Moneys.Value;
Fridges = player:WaitForChild("leaderstats").Fridges.Value;
Basic = player:WaitForChild("FridgeFolder").BasicFridge.Value;
}
local success, errormessage = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
if success then
print("Save Success")
else
print("Save Error")
warn(errormessage)
myDataStore:SetAsync(playerUserId, data)
end
end
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:wait()
load(player)
while true do
wait(420)
save(player)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
save(player)
end)
game:BindToClose(function()
for _, player in ipairs(Players:GetPlayers()) do
coroutine.wrap(save)(player)
end
end)