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.