need help with error on questit scripts pick up item

hi im trying to pick up an item from the ground and add it to inventory but when i click the item i get the error:
NullReferenceException
UnityEngine.Camera.ScreenPointToRay (Vector3 position) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Runtime/ExportGenerated/Editor/Graphics.cs:674)
GM+c__Iterator1.MoveNext () (at Assets/QuestIt/Scripts/GM.cs:138)

here is the script at the error

	IEnumerator scanForItems()
	{
		Ray mouseRay;
		RaycastHit hit;
		
		while(true)
		{
            if (Input.GetMouseButtonDown(0))
            {
                mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);

                if (Physics.Raycast(mouseRay, out hit, 100, ~(1 << 8)))
                {
                    if (hit.transform.GetComponent<item>())
                    {
                        if (IM.Ins.addItemToInventory(hit.transform.GetComponent<item>().itemPtr))
                            Destroy(hit.transform.gameObject);
                        else
                            hit.transform.GetComponent<item>().drop();
                    }
                    else
                    {
                        itemToPickUp = null;
                    }
					
					if (hit.transform.GetComponent<enemyControl>())
					{
						hit.transform.SendMessage("Die");
					}
                }
            }
			
			yield return null;
		}
	}

can anyone help out where it goes wrong

NullReference means it’s looking for an object but isn’t finding one. After you’ve destroyed it, maybe something is still looking for it.

it happens when i click on the item to add to inventory