I don't understand how to store the instances? I'm trying this but it won't work. Any fixes?
Serverscript
game.Players.PlayerRemoving:Connect(function(player)
warn("Data Saving")
local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."tHats01")
local statstorage = player:WaitForChild("Inventory").Hats:GetChildren()
for i = 1, #statstorage do
datastore:SetAsync(statstorage[i].Name, statstorage[i])
print("Saved Data Number ("..i..")")
end
print("Stats Successfully Saved!")
end)
game.Players.PlayerAdded:Connect(function(player)
warn("Data Loading")
local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."tHats01")
local MainCurrency = player:WaitForChild("MainCurrency")
if MainCurrency then
wait(1)
local stats = player:WaitForChild("Inventory").Hats:GetChildren()
for i = 1, #stats do
stats[i].Value = datastore:GetAsync(stats[i].Name)
print("stats number ("..i..") has been found")
end
end
end)

1 comment
which line is having the error?