I’ve have numerous reports in my game (1 in every 1,000 players) that they lost their data. I’ve tried some things with data failing to load, so I assume it’s with saving.
script:
function saveData(plr)
-- Retrieve player's current tycoon
local oldTycoon = plrCash[plr.Name].OwnsTycoon.Value
if module.currencySaves then
-- Save currency
local succ = false
local err
local count = 0
coroutine.resume(coroutine.create(function()
while not succ do
local succ, err = pcall(function()
store:SetAsync(plr.UserId.."-cash", plrCash:WaitForChild(plr.Name).Value)
end)
if succ ~= false then
count = 10
break
end
count += 1
print("running")
wait(1)
end
end))
end
if module.tycoonSaves and oldTycoon then
-- Save tycoon by adding object names to a table that
-- can later be unpacked by the loading function
local objects = plrCash[plr.Name].OwnsTycoon.Value.PurchasedObjects
local data = {}
for i,obj in ipairs(objects:GetChildren()) do
table.insert(data, obj.Name)
end
for i,obj in ipairs(removedObjects[plr.Name]) do
table.insert(data, obj)
end
local succ = false
local err
local count = 0
while not succ do
local succ, err = pcall(function()
-- Save object table to data store
store:SetAsync(plr.UserId.."-tycoon", data)
end)
if err then warn(err) end
if succ ~= false then
count = 10
break
end
count += 1
wait(1)
end
end
-- Replace tycoon with a new one for another player
if oldTycoon then
local newTycoon = game.ServerStorage:WaitForChild("TycoonClones"):FindFirstChild(oldTycoon.Name):Clone()
newTycoon.Parent = oldTycoon.Parent
oldTycoon:Destroy()
newTycoon.Main.Enabled = true
end
game.ServerStorage.PlayerCash[plr.Name]:Destroy()
end