Hey there! So I have an inventory saving system, it works just fine. But I was wondering how I could save and load a NumberValue with-in the tools?
In my case, Each of my tools has a NumberValue named “Level”.
Script:
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("TestSave3")
game.Players.PlayerAdded:Connect(function(player)
pcall(function()
local tool = dataStore:GetAsync("User-"..player.UserId)
if tool then
for i, v in pairs(tool) do
wait(0.01)
local toolFound
if game.ServerStorage.Tools:FindFirstChild(v) then
toolFound = game.ServerStorage.Tools:FindFirstChild(v)
elseif game.ServerStorage.Accessories.Hats:FindFirstChild(v) then
toolFound = game.ServerStorage.Accessories.Hats:FindFirstChild(v)
elseif game.ServerStorage.Accessories.Clothes:FindFirstChild(v) then
toolFound = game.ServerStorage.Accessories.Clothes:FindFirstChild(v)
end
if toolFound then
toolFound:Clone().Parent = player.Backpack
end
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
local toolsSave = {}
for i, tool in pairs(player.Backpack:GetChildren()) do
if tool then
table.insert(toolsSave,tool.Name)
end
end
dataStore:SetAsync("User-"..player.UserId, toolsSave)
warn("Saved Data!")
end)
end)