Fill Amount is not working

Hello everyone. Im new to Unity and i want to make healthbar. Everything was working fine until I ran into error. As you have seen from title, fill amount isn’t working for my image.
I nested canvas > background image > slider > health image for UI. For some reason, i can’t post photos.
Here is my script.

using UnityEngine;

using UnityEngine.UI;

public class Respawn : MonoBehaviour

{
[SerializeField] GameObject player;

[SerializeField] float playerMaxHealth;

private float playerCurrentHealth;

[SerializeField] float playerLifes;

[SerializeField] float monsterDamage;

[SerializeField] float DeadHeightY;
Vector3 spawnCoordinates;

[SerializeField] Image HealthBar;
void Start()
{
    spawnCoordinates = GameObject.Find("SpawnPoint").transform.position;
    spawnCoordinates.y += 10f;

    playerCurrentHealth = playerMaxHealth;

    HealthBar = GetComponent<Image>();
}

void Update()
{
    HealthBar.fillAmount = playerCurrentHealth / playerMaxHealth;
    if(playerCurrentHealth <= 0f)
    {
        Spawn();
    }
    if(player.transform.position.y <= DeadHeightY)
    {
        Spawn();
    }
}

private void OnCollisionEnter(Collision collision)
{
    if(collision.gameObject.name == "enemy")
    {
        playerCurrentHealth -= monsterDamage;
    }
}

private void Spawn()
{
    player.transform.position = spawnCoordinates;
    playerCurrentHealth = playerMaxHealth;
    playerLifes--;
}

}

I get an error : NullReferenceException: Object reference not set to an instance of an object
Respawn.Update () (at Assets/Scripts/Player/Respawn.cs:29)
Tell me if you need more info!

I suppose You have Serialized the variable HealthBar HealthBar = GetComponent<Image>(); with the intention of setting it up in the inspector, which is fine. But then in your Start method you set it (again?) HealthBar = GetComponent<Image>();.

My bet is you forgot to set the Image Component to the same object this script is attached to OR forgot to delete that line from the Start method.