Item Pickup randomly not working

I have a working item pickup with scriptable objects, but for some reason, some items will randomly not be able to get picked up. There’s no errors or anything. Here’s the interact (item pickup) code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Interact : MonoBehaviour
{
public Item item;
public float range = 5f;
private GameObject cam;
private GameObject camera2;
public LayerMask Item;
private GameObject pickItem;
private GameObject intObject;
private GameObject player;

	public void Start()
	{
	    cam = GameObject.FindWithTag("MainCamera");
	    camera2 = GameObject.FindWithTag("Camera2");
		player = GameObject.FindWithTag("Player");
		pickItem = GameObject.FindWithTag("Item");
	}

public void Update()
{
	if (Input.GetKeyDown(KeyCode.E))
    {
        InteractWith();
    }
}

public void InteractWith()
	{
		//checks if raycast hits item
		RaycastHit hit;
		if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, range, Item))
		{
			if (hit.transform.gameObject == this.gameObject)
			{
			print("Testing");
				if (pickItem != null)
				{
					bool wasPickedUp = Inventory.instance.Add(item);
					if (wasPickedUp)
						Destroy(gameObject);
					Debug.Log(hit.transform.name);
				}

				if (intObject != null)
				{

					Debug.Log("Interacting with" + transform.name);
				}
			}
		}
	}
}

Here’s the code block that add the item to inventory:

public bool Add (Item item)
{
    if(!item.isDefaultItem)
    {
        if(items.Count >= space)
        {
            Debug.Log("Not enough room.");
            return false;
        }
        items.Add(item);

        if(onItemChangedCallback != null)
            onItemChangedCallback.Invoke();
    }
    return true;
}

In your start command it looks like you’re finding any Gameobject with a tag “Item”. I’m assuming you have a more then one item on the ground so some pickup items will contain duplicates or the incorrect item you are aiming for. Your script is then not going passed the null check due to a previously destroy item from pickup.

For debuging purposes set all of your variables to public and click on them to see if they’re sharing the same object. I always set my variables to public at first then refactor later to avoid issues like this.

Also, do you have this attached to each item on the ground?