Help With Error NullReferenceException: Object reference not set to an instance of an object

hey so im pretty new with unity, and ive been having problems with a script, all giving the same error,

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

Iv’e looked around, and it seems like it normally means you don’t have the object the script is looking for named correctly, but afaik, I have the names right?
here’s the code

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

public class HeroHP : MonoBehaviour

{
public float heroHP = 100;
public Slider HP;
public float currentHP;

// Start is called before the first frame update
void Start(){
currentHP = heroHP;
}

// Update is called once per frame
public void GetHurt(float damage){
currentHP -= damage;
HP.value = currentHP; // Error Is Here

}
and i attached the screenshot of my inspector as well

any help is appreciated!

4478224–411868–Help.psd (464 KB)

  • use code tags when you put code on the forum
  • put the proper class on the the forum (HeroKill.cs), the error does not indicate the HeroHP.cs, it indicated the HeroKill.cs
  • also point out which one is the 19th line when you post the code here (if it does not translate to the 19th line…)
  • do not put psd on the post, upload screenshots and embed them (Upload a File button)