I need help again with health bars

I am making health bars in my game but they always go past the endpoint for the health bar I need help. What code do I do to make it stop at the end of the health bar?
nd how do I make a project score that does not go below 0 for bullets

1 Like

Perhaps using some form of if statement to stop the count from going down would help. Here I made this little game that uses a very simple health bar that works for what I made. I am sure there are more elegant solutions but go ahead and feel free to use some of my code.

In my layer update script

  //updates width for healthbar

healthBar.width = project.avatarHealth;

//Checks avatarHealth and if equals to 0
//loops and removes clones
//next timeline

if(project.avatarHealth === 0){
    for(let l of log.clones){
        l.remove();
    }
    for(let p of powerUp.clones){
        p.remove();
    }
    
    //set final score for game
    project.finalScore = project.globalScore;
    finalScoreText.setText(project.finalScore + "pts");
    
    //reset project settings
    project.timeLogValue = 0;
    project.timerLogValue = 0;
    project.timer = 0;
    project.speed = 10;
    project.GameOver = false;
    project.globalScore = 0;
    project.avatarSpeed = 25;
    project.avatarHealth = 99;
    
    //goes next frame
    gotoAndStop(3);
}

ifi-holidays202012-8-2020_12-27-01PM.wick (907.8 KB)