Data store isn’t working. It’s meant to save ores.
local datastore = game:GetService("DataStoreService")
local inventoryStore = datastore:GetDataStore("InventoryStore")
for _,v in pairs(game.ReplicatedStorage.Ores:GetChildren()) do
if v:IsA("Part") and v.Name ~= "Hay" then
local ore = Instance.new("NumberValue",script.Inventory)
ore.Name = v.Name
local Sellvalue = Instance.new("NumberValue",ore)
Sellvalue.Value = v:WaitForChild("Sell").Value
Sellvalue.Name = "SellValue"
elseif v.Name == "Hay" then
local Sell = Instance.new("NumberValue",v)
Sell.Value = v:WaitForChild("Sell").Value
Sell.Name = "SellValue"
end
end
game.Players.PlayerAdded:Connect(function(plr)
if plr then
local inv = script.Inventory
inv:Clone().Parent = plr
for _,v in pairs(inv:GetChildren()) do
print("Loading Data.")
v.Value = inventoryStore:GetAsync(plr.UserId..v.Name)
print("Loaded Data!",v.Value)
v.Changed:Connect(function()
print("Saving Data...")
wait(.3)
inventoryStore:SetAsync(plr.UserId..v.Name,v.Value)
print("Data Saved!")
end)
game.Players.PlayerRemoving:Connect(function()
for _,v in pairs(inv:GetChildren()) do
print("Saving Data...")
wait(.3)
inventoryStore:SetAsync(plr.UserId..v.Name,v.Value)
print("Data Saved!")
end
end)
end
end
end)