Object reference not set to an instance of an object? Looked everywhere for help.

I am here to Learn how to better debug c# scripts better any feed back is appreciated.
Here is the code in question:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BoxDMG : MonoBehaviour {
    float damage = 5f;
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}
    void OnTriggerEnter2D (Collider2D other)
    {
        if (other == null)
        {
            Debug.Log("other is null so fix it");
        }

        other.gameObject.GetComponent<HealthBar>().TakeDamage(damage);

        if (other.gameObject == null)
        {
            Debug.Log ("other.gameObject is null so fix it");
        }

    }
}

as you can see i have been trying to test everything and see what it is that is coming out as null
this script is put on a sprite that also as a Box Collider. the Health bar its referring to is here:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

    public class HealthBar : MonoBehaviour {
    public float curHealth = 4f;
    public float maxHealth = 10f;
    public bool playerDead = false;
    public Image Bar;
	
    // Use this for initialization
	void Start () {
        SetHealth();
    }

    // Update is called once per frame
    public void TakeDamage (float amount) {
        curHealth -= amount;
        SetHealth ();
    }
    public void SetHealth (){
        float healthPercent = curHealth / maxHealth;
        Bar.fillAmount = healthPercent;
    }

}

this script is attached to a UI element to display my health. it seems to work fine on its own. as when i set the health manually it decreased my health bar in the UI accordingly.

Whenever my player model touches the box that has the first script attached to it, the game pauses and i get this error:

NullReferenceException: Object reference not set to an instance of an object
BoxDMG.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/BoxDMG.cs:19)

Since line 19 is where “other” is stated, i figured that it was trying to tell me that the variable “other” was returning a null value or wasant attached to an object. but after testing using “return” commands and “DeBug.Log” commands to test, neither of those were true.

Please Help, thanks.

FIXED! thanks to Glurth and doublemax. HealthBar was attached to a ui element and not the player that was iteracting with the box to take damage. Here are the updated scripts:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class HealthBar : MonoBehaviour
{
    public float curHealth = 10f;
    public float maxHealth = 10f;
    public Image Bar;
   

    // Use this for initialization
    void Start()
    {
     
        SetHealth();
    }

    // Update is called once per frame
    public void TakeDamage(float amount)
    {
        curHealth -= amount;
        SetHealth();
    }
    public void SetHealth()
    {
        float healthPercent = curHealth / maxHealth;
        Bar.fillAmount = healthPercent;

        if (curHealth <= 0)
        {
            Death();
        }


    }
    public void Death()
    {
        SceneManager.LoadScene("DeathMenu");
    }
   
}

This is attached to the player then you drag and drop the healthbar sprite onto the “Bar” image variable i the inspector. here is the other script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BoxDMG : MonoBehaviour {
    float damage = 1f;
	
    void OnTriggerEnter2D (Collider2D other)
    {
        other.gameObject.GetComponent<HealthBar>().TakeDamage(damage);
    }
}

Thanks for the help. PEACE.