Saving Inventory Tools + Values In Tools

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)

Instead of only saving the tool names, you could save tool data. I’m guessing your current datastore looks something like this:

local dataToSave = {"Shovel", "Cap", "Jacket",}

You could change it to:

local dataToSave = {
    ["Shovel"] = {
        ["UsesRemaining"] = 100,
    },
    ["Cap"] = {
        ["Color"] = "Blue",
    },
    --etc...
}

You’d have to change how you load and save the data but this should work.

Basically what RoyStanford said, just save the values. It’s that simple!
if we have our dictionaries,
dataToSave - the items your saving, then
Item- the item and its details,
you should have no issue.