Hey,
I have been experiencing a problem in which I don’t know whos side it is on. So basically, I am currently in progress of creating a tycoon game for a studio-- with that comes saving. For this, I am using the standard DataStoreService with no module integration.
When the player leaves the game, I set it up so that game:BindToClose()
saves all of the players’ data inside of the game.
I print a message every time the data has been saved.
Inside of the bought index, there are 3 indexes for each ID of each building bought. The workers is the same except the index is completely sequential.
When I try to join the game again and I print the information retreived from the store, this is the information that I got:
It loses data.
I am wondering if anyone had experienced this before and how you fixed it. This is the code inside of the tycoon main script that allows the saving to happen.
function Tycoon:OnLeave(Player : Instance)
local Tycoon = Player:FindFirstChild("Tycoon").Value;
if not Tycoon then return end
local TycoonObj = TycoonFolders[Tycoon];
if _G.TycoonsSave == true then
local Bought = { };
for _, Button in next, TycoonObj.ButtonFolder:GetChildren() do
if Button.Bought.Value == true then print(Button) Bought[Button.ID.Value] = true; end
end
local Workers = TycoonObj.CurrentWorkers or { };
local saved;
local succ, err = pcall(function()
saved = TycoonStore:SetAsync(Player.UserId, {["bought"] = Bought, ["workers"] = Workers})
end)
if not succ then
warn("Failed to save!", err);
else
if saved then
warn("Saved.", saved, {["bought"] = Bought, ["workers"] = Workers})
end
end
end
wait(3)
TycoonObj:ResetTycoon()
end