Data doesn't save sometimes?

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
1 Like

I recommend to not use the default Data store service for bigger games with higher counts of people. It’s not a great service, for data saving and there is a lot of better ways to save data. I use the profile service which is made by devs, That have spent a long, long time for saving data. This is what I recommend, and connecting it so you slowly change from one data set to the other. Below I have a video (made by MonzterDEV) that’s made on the profile service & it explains it well. Profile Service Video

Thank you, it seems really easy to use. I think I’ll transfer to that method.

1 Like

It’s really easy, and well trusted, may take some time getting use to it but super amazing and some of the biggest roblox games use this service!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.