Unassigned reference is assigned and works despite the error... help!

Hi there, the situation is in the title. I’m trying to move a door upwards to open it to go to the next level once the victory condition is met. The door is a child to another game object that contains it as well as its framework and a light behind it, and the script is attached to the parent door. The variable in question is the child door, which I assigned by both using GetChild AND setting it up from inspector, yet in both situations i get the unassigned reference error. What’s worse is that the whole thing works perfectly and the door moves, but I just keep getting the error. It’s driving me crazy.

Relevant code:

metalDoor = transform.GetChild(1).gameObject;

    if (main.victory && metalDoor.transform.position.y < doorLimit)
       metalDoor.transform.position += Vector3.up * doorSpeed * Time.deltaTime;

Found the issue, I had the same script dragged to both the intended game object and one of its children accidentally. The parent was working and the errors were sent from the child.