So I have a MASSIVE problem,
My game with 150+ concurrent players is struggling to save data, and REVERSING players data!
These are some screenshots of one of the games players IN ORDER of them posting them.
As you can see, this player LOST data overtime, and he claimed:
“I rejoined multiple times, and only sometimes did I lose data”
Now, you CANNOT lose ANY of the first number, there’s simply no code in the game to do that.
I have also reviewed all the code in the game, and there is no code to remove from or reset any data.
This is the code I’m using for saving:
function SavePlayerData(Player, Id, BindToClose)
local DataToSave = {}
local Inventory = {}
for i, v in pairs(Player.leaderstats:GetChildren()) do
DataToSave[v.Name] = v.Value
end
for i, v in pairs(Player.Upgrades:GetChildren()) do
DataToSave[v.Name] = v.Value
end
for i, v in pairs(Player.TrailInventory:GetChildren()) do
Inventory[v.Name] = v.Name
end
if not Id and not table.find(Blacklist, Player.UserId) then -- Player = Player Instance
print("Saving data... (Plr Inst")
DS:UpdateAsync(Player.UserId.."DATA", function()
return DataToSave
end)
DS2:UpdateAsync(Player.UserId.."DATA", function()
return Inventory
end)
elseif Id and not table.find(Blacklist, Player.Name) then -- Player = Folder Instance
print("Saving data... (Cahce)")
DS:UpdateAsync(Player.Name.."DATA", function()
return DataToSave
end)
DS2:UpdateAsync(Player.Name.."DATA", function()
return Inventory
end)
end
print("Data saved!")
if not Id then table.remove(SavingDataIds, table.find(SavingDataIds, Player.UserId)) end
end
-- deleted some code that wasn't relevant
And these are the 2 only bits of code in the whole script to call the “SavePlayerData” function.
game.Players.PlayerRemoving:Connect(function(Player)
SavePlayerData(Player, false, false)
end)
game:BindToClose(function()
print('Saving data for all players..')
for Index, Player in pairs(ServerCache:GetChildren()) do
if not SavingDataIds[Player.Name] then
SavePlayerData(Player, true, true)
end
task.wait()
end
print('Saved all data!')
end)
-- deleted some code that wasn't relevant
Going to add on, the problem seems to only be with some of the players, not everyone. Me for example, can jump between servers and my data will be perfectly fine.