Cannot destroy items in player's backpack

So I’ve made a script that blocks, duplicating items in player’s inventory, but when I try to :Destroy() the item, it prints:
Something unexpectedly tried to set the parent of item to NULL while trying to set the parent of item. Current parent is Backpack.

Script:

local Players = game:GetService("Players")
local counter = 0
function playerAdded(player)
	player.CharacterAdded:Connect(function()
		local backpack = player:WaitForChild("Backpack")


		backpack.ChildAdded:Connect(function(item)
			counter = 0
			for i,v in pairs(player:GetDescendants()) do
			
				
				if v.Name == item.Name then
					
					counter += 1 
					
					
					if counter >= 2 then
						
						
						item:Destroy()
						print("Removed copy of: " .. item.Name)
					end
					
				end
			end
			
			
		
		end)
	end)
end

Players.PlayerAdded:Connect(playerAdded)

I think the issue is that you’re trying to destroy it immediately after it being added to your backpack. Try adding a wait somewhere to give it a chance before destroying

3 Likes

Do u get any kind of errors if so can u share it?