DataStoreService unable to withhold data?

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.
image

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:
image

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

I’m fairly certain that it’s because your keys are numerical with gaps missing. To fix this, try making your indexes strings, eg.

['1'] = true; 
['3'] = true
--- etc

I don’t that’s the solution. I tried it and it had the same result.
image

image

Maybe try seeing if you can give each button some identifier like “Button1”, “Button2” for the index instead of a number


Everything looks fine to me, what I recommend is to save the entire thing inside a table and get the whole player saved table, it makes it much easier to save all forms of data and it may solve your entire issue.


Hey, I just realized that the storing works perfectly fine inside of the normal ROBLOX player but doesn’t work inside of studio. Weird thing but it is whatever.

1 Like

I think it’s happening because for whatever reason Roblox thinks it’s either a mixed table, or it’s using something like ipairs on the backend which doesn’t work with tables that have missing values.