My DataSaving system is not working, and I’m trying to save the values in a folder, which is a number value if it makes sense. I also want to save the value of the number value.
Script:
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("PlayerData")
game.Players.PlayerAdded:Connect(function(plr)
local stockdata = nil
pcall(function()
stockdata = dataStore:GetAsync(plr.UserId.."Stock")
end)
if stockdata ~= nil then
repeat wait(.1) until plr:FindFirstChild("ItemsInStock", true)
for i, v in pairs(stockdata) do
if v >= 1 then
local newVal = Instance.new("NumberValue", plr.ItemsInStock)
newVal.Name = v.Name
newVal.Value = v
end
end
else
return
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local items = {}
for _, item in pairs(plr.ItemsInStock:GetChildren()) do
local newVal = Instance.new("NumberValue")
newVal.Name = item.Name
newVal.Value = item.Value
items[newVal.Name] = newVal.Value
end
pcall(function()
dataStore:SetAsync(plr.UserId.."ItemsInStock", pets)
end)
end)
game:BindToClose(function()
wait(3)
end)