Script that works, throws in errors

using UnityEngine;
using System.Collections;

public class NumberPlate : MonoBehaviour {

    public string currentName;
    GameObject plate;
    TextMesh plateText;

    void Update()
    {
        plate = GameObject.FindGameObjectWithTag("NumberPlate");

        plateText = plate.GetComponentInChildren<TextMesh>();

        plateText.text = currentName;

        if (!plate)
            return;

        if (!plateText)
            return;
    }
}

At line 14, I get object not set to an instance of an object, but I’ve saftey checked that with if it’s not there it should just return. Any answers would be great!

A method like Update() is executed line by line. A “safety check” therefore must come before actually using the variable. You simply need to move the if check to line 13.

     void Update()
     {
         plate = GameObject.FindGameObjectWithTag("NumberPlate");

         if (!plate)
             return;

         plateText = plate.GetComponentInChildren<TextMesh>();

         if (!plateText)
             return;

         plateText.text = currentName;

     }
 }

Oh man bow did I miss it! Thank you very much to those who answered! Definitely wasn’t thinking last night.

Cheers