Coroutine error

I have a coroutine that should simulate movement, but I keep getting this error after the first if statement executes once:

NullReferenceException: Object reference not set to an instance of an object
TrainMover+<MoveNX>c__Iterator1.MoveNext () (at Assets/Scripts/TrainMover.cs:117)

Here is the script:

IEnumerator MoveNX()
{
    if (Vector3.Distance(gameObject.transform.position, GameObject.Find("Target").transform.position) >= 0.1)
    {
        gameObject.transform.position -= new Vector3(0.1f, 0, 0);
        yield return new WaitForSeconds(0.1f);
    }
    if (Vector3.Distance(gameObject.transform.position, GameObject.Find("Target").transform.position) < 0.1)
    { 
        Destroy(GameObject.Find("Target"));
        moving = false;
        StopCoroutine(MoveNX());
    }
}

Can you please help us by telling that which line is getting null references because in the snippet you have provided doesn’t contain any 117 line number

I am assuming that the script is not able to find the ‘Target’. Can you please print it…
so that it will confirm that whether it is null or not.

Second No need to write again & again

GameObject.Find("Target")

Just find it in initial/start of the code and store the reference. > then use that reference everywhere. Like

GameObject target =   GameObject.Find("Target");

Now use ’ target ’ everywhere.