The player is not taking damage

Script 1:

bool isDead = playerScript.TakeDamage(theFinalSide);

Player Script:

public int maxHP = 10;
public int currentHP;

private void Start()
    currentHP = maxHP;
public bool TakeDamage(int damage)
    currentHP -= damage;
    if (currentHP <= 0)
        return true;
        return false;

I have a dice where whenever the dice is rolled, the number that the dice lands on (“finalSide”) does damage to the player.


  • the player currentHP is not setting itself to maxHp eventhough I put it in void Start(), I have to manually set it to the maxHP in the player prefab
  • the instantiated player is not taking damage but the prefab of the player takes damage
  • When playing again, the player prefab’s currentHP sets itself to the previous game currentHealth instead of setting it to maxHP, so i have set it manually again

Full Script of Script 1:

IEnumerator PlayerAttack()
    int randomSide = 0;
    int finalSide = 0;

    for (int i = 0; i <= 20; i++)
        randomSide = Random.Range(0, 6);
        diceSpriteRenderer.sprite = diceSides[randomSide];

        yield return new WaitForSeconds(0.05f);
    finalSide = randomSide + 1;
    theFinalSide = finalSide;
    if (nextTurn == 1) //player turn
        bool isDead = enemyScript.TakeDamage(theFinalSide);
        if (isDead)
            battleStatus = BattleState.Victory;
            //battleStatus = BattleState.EnemyTurn;
            nextTurn *= -1;


    Debug.Log("PlayerDice:" + " " + theFinalSide);
    Debug.Log("playerHP:" + " " + playerScript.currentHP);
    Debug.Log("enemyHP:" + " " + enemyScript.currentHP);

It’s hard to tell your issue without all the details, so here are some general tips:

-Add more Debug.Logs near the actual Damage and HP loss for the currentHP. For instance, right before and after “bool isDead = enemyScript.TakeDamage(theFinalSide);”

-For currentHP, try setting it as [SerializeField] private and use set/get to handle it to help control what accesses it.

-For “bool isDead = enemyScript.TakeDamage(theFinalSide);”, did you possibly mean “playerScript” and not “enemyScript”?

-When you start up the player with the initialized health values, did you update it in the Inspector as well? Changes in the Inspector override the default values in the script.

I meant playerScript
Thank you for helping, I’ll try it out