# Scoring system in a game

**URL:** <https://forum.kirupa.com/t/scoring-system-in-a-game/238809>\
**Category:** programming\
**Created:** [September 15, 2007, 3:04pm UTC](https://forum.kirupa.com/t/scoring-system-in-a-game/238809 "2007-09-15T15:04:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fw2803](https://avatars.discourse-cdn.com/v4/letter/f/e5b9ba/32.png) [@fw2803](https://forum.kirupa.com/u/fw2803)\
**Post date:** [September 15, 2007, 3:04pm UTC](https://forum.kirupa.com/t/scoring-system-in-a-game/238809/1 "2007-09-15T15:04:50Z")

</div>

Hi there  
I’m now creating a scoring system for my game. So when the player destroys an enemy, the score will hop up. There’s a big problem.

In my game, every enemy building and unit has a health value. When the value drops below 0, it is dead.

```auto

onClipEvent (load) {
  var health = 100
}
onClipEvent (enterFrame) {
  if (health <= 0) {
    health = 0
    _root.score += 200
  }
}

```

So if I code it like this, the score will soar up continuously by 200 at a time. Then I thought of defining a boolean like this:

```auto

onClipEvent (load) {
  var health = 100
  var scored = false
}
onClipEvent (enterFrame) {
  if (health <= 0) {
//the health value must be set back to zero otherwise the health bar will grow towards the negative side
    scored = true
    health = 0
    _root.score += 200
  }
  if ((scored == true) and (health <= 0)) {
//so if the player shoots the building again, the score won't grow anymore.
    _root.score += 0
  }
}

```

However, it did not work. How am I supposed to write this part of the script?

Thanks a lot.
