Referencing playerHealth (from a separate script) in an if statement

So I have a playerController and hudController. Within the hudController I have a health system with a field called “currentHealth”

within the playerController I have the following code:

hudController playersHealth;

void Start()

{

playersHealth = GetComponent<hudController>();

}

void stateManagement()

{

  if (playersHealth.currentHealth == 0)

  {

       state = State.Dying;

     playAnim.SetTrigger("isDead");

       Invoke("ReloadLevel", 2f);

   }

}

Am I missing something obvious here? as far as I can tell this should be working…

I figured it out, was a f*cking moron and didn’t put my player reference into my getcomponent

Change playersHealth = GetComponent to thePlayer.GetComponent

with “thePlayer” meaning find gameobject with tag “player”.