Help with equipping a saved weapon

So I have a datastore that saves the serial number of the current equipped weapon. The only problem I currently have is that it due to the fact that you can get duplicated weapons, when rejoining the game it’s hard to get just one of the weapons to be equipped.

So a player joins and equips the sword, it will get the swords serial number and store it in a equipStore. This is all works.

Now the player gets the same sword again, this is would increase the quantity of the weapon by + 1.

Now the player leaves and joins back, the how can I make it so when the play joins back it only gives them one of the weapons, as I currently have a set up in a for loop and loops the quantity of the weapon, and puts it inventory, so if It was to be equipped it would equip both of the swords.

So my first idea was this:
    EquipGive.GiveEquippedItem = function(NAME_OF_ITEM, item, player, animation, data)
    	local Inv = player.PlayerGui.Inventory.Inventory
    	if NAME_OF_ITEM == "Weapons" then 
    		local Tool = item:Clone() -- Clones the item
    		Tool.Parent = player.Character -- Gives it to player
    		Tool.Name = "EquippedWeapon" -- Called it EquippedWeapon
    		player.Character.Animate.toolnone.ToolNoneAnim.AnimationId = "http://www.roblox.com/asset/?id="..animation
    		for i, v in pairs(player.PlayerGui.Inventory.Inventory.WeaponsInv:GetChildren()) do
    			print(i,v)
    		end
    		-- FInd the frame, check for players inv, weaponinv, for loop all of the things inside of the frames
    		

    	end
    end

This would work only if the weapons quantity was 1. Because it is now 2 it will do this twice.

This is all I have so far, this is the script that gives the items to the inventory:

add.AddedEvent = function(item, class, player) -- Starting the game and gaining something like a sword  (class - Weapon/Potion/Armour)
	local items = ReplicatedStorage[class]:GetChildren()

	if item then	
		for num, rarity in pairs(script.Rarities:GetChildren()) do
			if item.Stats.Rarity.Value == rarity.Name then	
				local rare = rarity:Clone()	-- Clone the rarity ui
				local clone = item:Clone() -- Cloning the tool
				clone.Parent = rare.ItemView -- Setting the tool to the viewportFrame
				local bp = item:Clone()
				bp.Parent = player.Backpack
				local Camera = Instance.new("Camera") -- Creating a Camera
			    rare.ItemView.CurrentCamera = Camera -- Setting the viewports CurrentCamera to the new one
				Camera.Parent = rare.ItemView -- The camera parent is the viewportFrame
				Camera.CFrame = CFrame.new(item.Handle.Position + Vector3.new(6, 4, -1), item.Handle.Position)--Camera.CFrame = CFrame.new(Vector3.new(0,3,0), v.Handle.Position)-- Position of the camera
				rare.Parent = player.PlayerGui.Inventory.Inventory[class.."Inv"]
				print("Added "..item.Name.." to your inventory")
			end
		end	
	end
end

and this would add it to the inventory, I could add a check of some sort to see if the item has been added to the inventory, not sure how.

This is the script that equips it when the item is pressed in the inventory.

add.Equip = function(player, item, animation, frame)
	local Tool = item:Clone() -- Clones the item 
	Tool.Parent = player -- Gives it to player
	Tool.Name = "EquippedWeapon"
	local char = player
	char.Animate.toolnone.ToolNoneAnimation.Id = "http://www.roblox.com/asset/?id="..animation -- Holding animation for the sword.
	frame.Parent = frame.Parent.Parent -- the frame which the sword is in the inventory 
	frame:TweenPosition(UDim2.new(-1.015, 0, 0.771, 0),"Out","Quart",0.1) -- Side of the screen

end

If there is any questions you need to ask, as I may have skipped over things, let me know and I will answer them. Any help would be appreciated.

I have solved it for now, I’ll keep on testing with this and see if I solved it.