X.Text just uses random values

I have some code, embedded below, and for some reason, Debug.Log(textNum) outputs the number I want, but Number.text doesn’t use that number, even though I’m using literally the same variable. Does anyone have any insight?

    string textNum = lastID.ToString();
    Debug.Log(textNum);
    Number.text = textNum;

There’s not really anything that could go wrong with this code, so I guess the problem lies elsewhere. Possible causes would be

  1. Another line of code or another script is chaning Number.text as well.
  2. You have another instance of this script somewhere that overwrites Number.text.
  3. You have assigned the wrong object (or none) to Number.

My bets are on 2., but the others are possible too. Build a minimal example - a new scene with just the Text object and this script in it, then see what happens. Also look in the console for error messages and if your Debug.Log happens multiple times.