DataStore trouble in my new update

Hello everyone, I have my game and development place for it. And when I finished new update for the game, I published it, but… My DataStore got broken. Let me explain what happend.

I have Two Scripts with DataStores:
- Main Data Store (Contains: Coins, Treasures Found, Halos)
- Treasures Data Store (Contains: Treasures)

And my Main DataStore is saved everything in the game, but not the Treasures DataStore.
In the Main DataStore, “Treasures Found” value, says that player found a lot of treasures, for example 20/50. But when you open index, you will see that every treasure is closed. And, If you try to find treasure that you already found, it won’t say that you already picked up it.

Here is Screenshot of the problem:

Collected 23 treasures, but everything is closed.
I don’t know what should I do, I didn’t change DataStore Key.

But what I actually changed, it’s a script.
New Version of Treasure DataStore Script:

local players = game:GetService("Players")
local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("dataStoreTreasures~--{&q8972^123(63&4)*0}")

players.PlayerAdded:Connect(function(plr)
	wait(1)
	local userID = "id_"..plr.UserId
	local data = ds:GetAsync(userID)
	if data then
		for i,v in pairs(data) do
			local item = plr.Treasures:FindFirstChild(i)
			if item then
				item.Value = v.Value
			end
		end
	end
end)
function save(plr)
	local data = {}
	local userID = "id_"..plr.UserId
	for i,v in pairs(plr.Treasures:GetChildren()) do
		data[v.Name] = v.Value
	end
	local success, result = pcall(function()
		ds:SetAsync(userID, data)
	end)
	if success then print("TreasuresData successfuly saved!")
	else warn(result) end
end
players.PlayerRemoving:Connect(save)
game:BindToClose(function()
	for i,plr in pairs(players:GetPlayers()) do
		save(plr)
	end
end)

Old Version of Treasures DataStore Script:

local players = game:GetService("Players")
local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("dataStoreTreasures~--{&q8972^123(63&4)*0}")

players.PlayerAdded:Connect(function(player)
	wait(1)
	local userID = "id_"..player.UserId
	
	local treasures = {}
	for i,v in pairs(player.Treasures:GetChildren()) do
		if v:IsA("BoolValue") then table.insert(treasures, v) end
	end
	local getSaved = ds:GetAsync(userID)
	if getSaved then
		--for i,v in pairs(treasures) do
		--	print(i,v)
		--	player.Treasures:FindFirstChild(treasures[v]).Value = getSaved[i]
		--end
		player.Treasures:FindFirstChild("TowerChest").Value = getSaved[1]
		player.Treasures:FindFirstChild("BedChest").Value = getSaved[2]
		player.Treasures:FindFirstChild("BorderChest").Value = getSaved[3]
		player.Treasures:FindFirstChild("BossChest").Value = getSaved[4]
		player.Treasures:FindFirstChild("BoxChest").Value = getSaved[5]
		player.Treasures:FindFirstChild("CactusChest").Value = getSaved[6]
		player.Treasures:FindFirstChild("CaveChest").Value = getSaved[7]
		player.Treasures:FindFirstChild("FireChest").Value = getSaved[8]
		player.Treasures:FindFirstChild("HouseChest").Value = getSaved[9]
		player.Treasures:FindFirstChild("NPCChest").Value = getSaved[10]
		player.Treasures:FindFirstChild("ObbyChest").Value = getSaved[11]
		player.Treasures:FindFirstChild("OfficeChest").Value = getSaved[12]
		player.Treasures:FindFirstChild("PipeChest").Value = getSaved[13]
		player.Treasures:FindFirstChild("SandChest").Value = getSaved[14]
		player.Treasures:FindFirstChild("SignChest").Value = getSaved[15]
		player.Treasures:FindFirstChild("TankChest").Value = getSaved[16]
		player.Treasures:FindFirstChild("TrampolineChest").Value = getSaved[17]
		player.Treasures:FindFirstChild("TreeChest").Value = getSaved[18]
		player.Treasures:FindFirstChild("UmbrellaChest").Value = getSaved[19]
		player.Treasures:FindFirstChild("WindowChest").Value = getSaved[20]
		
		
	else
		local saveValues = {
			player.Treasures:FindFirstChild("TowerChest").Value,
			player.Treasures:FindFirstChild("BedChest").Value,
			player.Treasures:FindFirstChild("BorderChest").Value,
			player.Treasures:FindFirstChild("BossChest").Value,
			player.Treasures:FindFirstChild("BoxChest").Value,
			player.Treasures:FindFirstChild("CactusChest").Value,
			player.Treasures:FindFirstChild("CaveChest").Value,
			player.Treasures:FindFirstChild("FireChest").Value,
			player.Treasures:FindFirstChild("HouseChest").Value,
			player.Treasures:FindFirstChild("NPCChest").Value,
			player.Treasures:FindFirstChild("ObbyChest").Value,
			player.Treasures:FindFirstChild("OfficeChest").Value,
			player.Treasures:FindFirstChild("PipeChest").Value,
			player.Treasures:FindFirstChild("SandChest").Value,
			player.Treasures:FindFirstChild("SignChest").Value,
			player.Treasures:FindFirstChild("TankChest").Value,
			player.Treasures:FindFirstChild("TrampolineChest").Value,
			player.Treasures:FindFirstChild("TreeChest").Value,
			player.Treasures:FindFirstChild("UmbrellaChest").Value,
			player.Treasures:FindFirstChild("WindowChest").Value
		};
		ds:GetAsync(userID, saveValues)
	end
end)
players.PlayerRemoving:Connect(function(player)
	local userID = "id_"..player.UserId
	local saveValues = {
		player.Treasures:FindFirstChild("TowerChest").Value,
		player.Treasures:FindFirstChild("BedChest").Value,
		player.Treasures:FindFirstChild("BorderChest").Value,
		player.Treasures:FindFirstChild("BossChest").Value,
		player.Treasures:FindFirstChild("BoxChest").Value,
		player.Treasures:FindFirstChild("CactusChest").Value,
		player.Treasures:FindFirstChild("CaveChest").Value,
		player.Treasures:FindFirstChild("FireChest").Value,
		player.Treasures:FindFirstChild("HouseChest").Value,
		player.Treasures:FindFirstChild("NPCChest").Value,
		player.Treasures:FindFirstChild("ObbyChest").Value,
		player.Treasures:FindFirstChild("OfficeChest").Value,
		player.Treasures:FindFirstChild("PipeChest").Value,
		player.Treasures:FindFirstChild("SandChest").Value,
		player.Treasures:FindFirstChild("SignChest").Value,
		player.Treasures:FindFirstChild("TankChest").Value,
		player.Treasures:FindFirstChild("TrampolineChest").Value,
		player.Treasures:FindFirstChild("TreeChest").Value,
		player.Treasures:FindFirstChild("UmbrellaChest").Value,
		player.Treasures:FindFirstChild("WindowChest").Value
	};
	local success, result = pcall(function()
		ds:SetAsync(userID, saveValues)
	end)
	if success then print("TreasuresData successfuly saved!")
	else warn(result) end
end)

If somebody know solution for this problem, it would be really appreciated! Thanks.

2 Likes

I would put this in a pcall since it can error and break your script!

Can you try your game without data and try it?

I think it is happening because the index of the old data is numbers, not names.

I don’t think it’s an issue, because when I’ve clear all my data and then played some time, it saved everything.

Yes but especially when the Roblox Server’s down it can start to error and your whole script will break!

Okay, I’ll try to do that right now.

Did you check to see if the data even exists anymore?

I did that, now it’s again broken! My treasures got reset and now problem not only for players that don’t play, but for me either lol.

Screenshot:

game:BindToClose(function()
	for i,plr in pairs(players:GetPlayers()) do
		save(plr)
	end
end)

do you really need this?

This does not relate to the problem nor fix it in any way. This code saves player data when the server is shutdown.

I don’t really know, I saw this script on devforum, and it says that it’s for, when developer shutdown servers

I don’t even know how to check it…

Read this thread about how to check the data in your datastore.


What should I do with that information?
(thats treasure data store)

You don’t have any data in the datastore. Either you changed the datastore name to something else or when it saved, it override all of your already existing data.

1 Like

I mean, I don’t know why but there is a lot of random data store keys that I never change, only if in development place to test the game. But, now I have two questions…
image

First Question - How to fix that?
Second Question - Why there is no data? And why it reseting every time if I’ll change code?
(that’s three question but nvm)

Also, it’s not the first time it happens to me, already happend something like this in my old games.
EDIT: It’s only happens to the Treasures DataStore (I don’t know why)

You can’t fix a datastore that has deleted or non-existing data.

Okay, so, why then it’s deleting with no reason?

Can someone help fixing this? I need solution, please.

Okay. Let me try and help;

We don’t have access to your place, nor much information on the past and what it looks like now. You need to first get the list of people in the treasure datastore and print them out. If nothing prints out, the data has been wiped, you can’t get it back and there is nothing that can solve it. If the data prints out, then there is no problem with the datastore and you just aren’t getting it correctly.

You can still have nothing printed out if you did it wrong. I would first print out the data, then loop through it, and then loop 1 more time.

This should give you an idea of what to do next. If not, reply. If it does work, I will not be able to help you anymore. (Basically, I will not be writing code to fix your problem. This is a learning opportunity, and I don’t get any sort of compensation from this except enhancing my problem solving skills. Feel free to still ask questions.)

1 Like