I have this inventory save script that should work and I think its saving the data but its not loading the data can you tell me what i'm doing wrong?
Here's the script!
local inventoryData = game:GetService("DataStoreService"):GetDataStore("inventoryTest")
local inventoryHolder = script.InventoryHolder
game.Players.PlayerAdded:Connect(function(player)
local Key = "Player-ID"..player.UserId
local GetSave = inventoryData:GetAsync(Key)
local DataBaseFolder = Instance.new("Folder", player)
DataBaseFolder.Name = "Inventory"
for i, inventory in pairs(inventoryHolder:GetChildren()) do
local newInventory = Instance.new(inventory.ClassName)
newInventory.Name = inventory.Name
newInventory.Value = inventory.Value
newInventory.Parent = DataBaseFolder
end
if GetSave then
for i,v in pairs(GetSave) do
local testValue = game.ServerStorage.TrailValues:FindFirstChild(v)
for i = 1, #testValue do
if testValue then
local clone = testValue()
clone.Parent = DataBaseFolder
clone.Name = v
end
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Key = "Player-ID"..player.UserId
local DataBaseFolder = player.Inventory
local InventoryToSave = {}
for i,v in pairs(DataBaseFolder:GetChildren()) do
table.insert(DataBaseFolder:GetChildren(), v.Name)
end
inventoryData:SetAsync(Key, InventoryToSave)
end)
