I have a datastore system where it saves the tools in the player’s storage by storing the name of the values and then the amount. Then when the player loads in it grabs the items from server storage and puts it in their storage. It worked great. Recently when I started adding items to the server storage I found that it would only save the “OG” items in the game. I thought it could be from the new items I was implementing but to test this I duplicated an “OG” item and renamed it. It wouldn’t save. This means the datastore broke and only saves what it remembers was in the folder before? Any fix to this? Code below.
local DSS = game:GetService(“DataStoreService”)
local DS = DSS:GetDataStore(“Storage”)
local All = game.ServerStorage:WaitForChild(“Trade”)
game.Players.PlayerAdded:Connect(function(Player)
local Inventory = Instance.new(“Folder”,Player)
Inventory.Name = “Storage”
local Data
local Success,err = pcall(function()
Data = DS:GetAsync(Player.UserId)
end)
if not Success then
Player:Kick("Error loading data: "…err)
else
if not Data then
Data = {}
end
for index,value in pairs(Data) do
if All:FindFirstChild(value) then
All:FindFirstChild(value):Clone().Parent = Inventory
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
if Player:FindFirstChild(“Storage”) then
local t = {}
for index,value in pairs(Player:FindFirstChild(“Storage”):GetChildren()) do
if game.ServerStorage.Trade:FindFirstChild(value.Name) then
t[#t+1] = value.Name
end
end
DS:SetAsync(Player.UserId,t)
else
warn("Storage missing in player " … Player.Name)
end
end)
game:BindToClose(function()
task.wait(3)
end)