Object not being dragged

Trying to drag a GameObject with a Sprite renderer and 2d Collision Box. I try to run this:

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

public class pieceMovement : MonoBehaviour
{

    private float startPosX;
    private float startPosY;
    private bool beingHeld = false;

    // Update is called once per frame
    void Update()
    {
        
        if(beingHeld)
        {
            
            Vector3 mousePos;
            mousePos = Input.mousePosition;
            mousePos = Camera.main.ScreenToWorldPoint(mousePos);

            this.gameObject.transform.localPosition = new Vector3(mousePos.x, mousePos.y, 0);

        }

    }

    private void OnMouseDown()
    {

        if(Input.GetMouseButtonDown(0))
        {

            Vector3 mousePos;
            mousePos = Input.mousePosition;
            mousePos = Camera.main.ScreenToWorldPoint(mousePos);

            beingHeld = true;

        }

    }

    private void OnMouseUp()
    {

        beingHeld = false;

    }
}

But I get this error:

NullReferenceException: Object reference not set to an instance of an object
pieceMovement.OnMouseDown () (at Assets/pieceMovement.cs:37)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)

One problem I see is this :

 Vector3 mousePos;
             mousePos = Input.mousePosition;
             mousePos = Camera.main.ScreenToWorldPoint(mousePos);

Should look more like this:

public Vector3 mousePos;

void Update()
{
    mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}

And secondly :

/// makes no sense
this.gameObject.transform.localPosition = new Vector3(mousePos.x, mousePos.y, 0);

// if this script is the object in questions script
transform.position = new Vector2(mousePos.x, mousePos.y);

// if this object in question is in another script
otherObject.transform.position = new Vector2(mousePos.x, mousePos.y);

^ This is of course assuming that you are not dealing with parents, and are not trying to move the childs local position relative to the parents position.

But this is the reference to the script in question. So if your trying to call the script you are already in? this is redundant. That would only be needed if this was a parent class that was hold Lists of the children scripts, but the function itself was in the parent, and the child was calling it? then yes, you would need to say something like:

public void StartBeingDragged()
{
     otherObject = (otherClassName)this.gameObject;
}

^ Very poorly said, but hopefully you get the idea.