Tool saving on specific tools

Hello everyone. I’m making a game and I want specific tools to save. I got this script online:

local Inventory = {}

local function Spawned(Char)
	local Plr = game.Players:GetPlayerFromCharacter(Char)
	for i,v in pairs(Inventory[Plr]) do
		if Plr['Backpack']:findFirstChild(v.Name) then
			Plr['Backpack'][v.Name]:Destroy()
		end
		v.Parent = Plr['Backpack'] 
	end
	Inventory[Plr] = {}
	Char:WaitForChild('Humanoid').Died:connect(function()
		for i,v in pairs({Plr['Backpack'], Char}) do
			for ii,vv in pairs(v:GetChildren()) do
				if vv:IsA('Tool') then
					table.insert(Inventory[Plr], vv:Clone())
					vv:Destroy()
				end
			end
		end
	end)
end

game.Players.PlayerAdded:connect(function(Plr)
	Inventory[Plr] = {}
	local Char = Plr.Character or Plr.CharacterAdded:wait()
	Spawned(Char)
	Plr.CharacterAdded:connect(Spawned)
end)

but there are some tools that duplicate because they are gamepass tools. I’m not 100% sure why they duplicate, but it’s a problem. If anyone could help me with this, it would be very appreciated! :slight_smile:

2 Likes

Is this script obfuscated or something?

You can just find the tool and check if it already exists and stop adding it a 2nd time.

You can make it so that if amount of a specific tool is equal or less than one dont destroy but then if its greater destroy that number of that tool