My script for saving data (below) is only saving part of the time. I have a feeling I know why, but I’m not totally sure how I can go about fixing this issue.
And for anyone wondering, the global variable “keys” is located in the same script, so it can’t be nil, right???
function savePlayerData(player)
local leaderstats = player.leaderstats
dataStoreService:GetDataStore(_G.keys.GeneralData):SetAsync(player.UserId, {
["Wins"] = leaderstats.Wins.Value,
["Losses"] = leaderstats.Losses.Value,
["Level"] = leaderstats.Level.Value,
["Experience"] = leaderstats.Experience.Value,
["Coins"] = leaderstats.Coins.Value,
["Gems"] = leaderstats.Gems.Value,
["Equipped"] = {
["Skin"] = tostring(player.EquippedData:GetAttribute("Skin")), ["Effect"] = tostring(player.EquippedData:GetAttribute("Effect")), ["Emote"] = tostring(player.EquippedData:GetAttribute("Emote"))
}}
);
end
game.Players.PlayerRemoving:Connect(function(player)
local success,err
repeat wait() success,err = pcall(function() savePlayerData(player) end) until success
end)
game:BindToClose(function()
for _,player in pairs(game.Players:GetPlayers()) do
local s = coroutine.wrap(function()
savePlayerData(player)
end)
s();
end
end)