# I need help with health bars

**URL:** <https://forum.makecode.com/t/i-need-help-with-health-bars/27960>\
**Category:** Help\
**Created:** [March 27, 2024, 12:18am UTC](https://forum.makecode.com/t/i-need-help-with-health-bars/27960 "2024-03-27T00:18:23Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Davida](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@Davida](https://forum.makecode.com/u/Davida)\
**Post date:** [March 27, 2024, 12:18am UTC](https://forum.makecode.com/t/i-need-help-with-health-bars/27960/1 "2024-03-27T00:18:23Z")

</div>

I keep getting error code 981 and I really dont know what it is

---

<div class="post-metadata">

**Author:** ![Luke](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/luke/32/32519_2.png) [@Luke](https://forum.makecode.com/u/Luke)\
**Post date:** [March 27, 2024, 12:22am UTC](https://forum.makecode.com/t/i-need-help-with-health-bars/27960/2 "2024-03-27T00:22:05Z")

</div>

share code pls

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [March 27, 2024, 12:28am UTC](https://forum.makecode.com/t/i-need-help-with-health-bars/27960/3 "2024-03-27T00:28:46Z")

</div>

Welcome, @Davida !

It sounds like you’re trying to run a project on a hardware device. Error code 981 is called _cast on undefined_, where you are using a variable that does not have a value.

Common hardware error codes are listed here:

> **[Errors on Hardware](https://arcade.makecode.com/hardware/errors)**
>
> When developing games, you might run into bugs that cause your game to crash.
> In the browser, these errors can be identified by using the debugger
> or by reading the messages displayed along with the error.

As @Luke mentioned, if you need further help, then share your project with us so that we can try to give more specific assistance.

---

<div class="post-metadata">

**Author:** ![Davida](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@Davida](https://forum.makecode.com/u/Davida)\
**Post date:** [March 27, 2024, 3:21pm UTC](https://forum.makecode.com/t/i-need-help-with-health-bars/27960/4 "2024-03-27T15:21:39Z")

</div>

> **[Microsoft MakeCode Arcade](https://arcade.makecode.com/#editor)**
>
> Develop your programming skills by quickly creating and modding retro arcade games with Blocks and JavaScript in the MakeCode editor

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [March 27, 2024, 3:26pm UTC](https://forum.makecode.com/t/i-need-help-with-health-bars/27960/5 "2024-03-27T15:26:13Z")

</div>

@Davida To share code, use the **share** button when you have the project open.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/5/5c1354ba3dd7d7b0ef11401da58fbe19fbefd360.png)

MakeCode will give you a web link to your published project after you have shared it. You can use that link to share your project with us.

---

<div class="post-metadata">

**Author:** ![Davida](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@Davida](https://forum.makecode.com/u/Davida)\
**Post date:** [March 27, 2024, 4:57pm UTC](https://forum.makecode.com/t/i-need-help-with-health-bars/27960/6 "2024-03-27T16:57:14Z")

</div>

Is this ok?

> **[Space arcade](https://arcade.makecode.com/98694-30514-44436-90099)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

Its not done yet i still havent figured out the problem

---

<div class="post-metadata">

**Author:** ![Davida](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@Davida](https://forum.makecode.com/u/Davida)\
**Post date:** [March 27, 2024, 4:59pm UTC](https://forum.makecode.com/t/i-need-help-with-health-bars/27960/7 "2024-03-27T16:59:01Z")

</div>

I think i have figured the problem but it still sometimes occures when I destroy two asteroids at the same time.  
Updated code: [https://makecode.com/\_e1kfmeV8bdgE](https://makecode.com/_e1kfmeV8bdgE)

---

<div class="post-metadata">

**Author:** ![Sparks](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sparks/32/8161_2.png) [@Sparks](https://forum.makecode.com/u/Sparks)\
**Post date:** [March 27, 2024, 5:10pm UTC](https://forum.makecode.com/t/i-need-help-with-health-bars/27960/8 "2024-03-27T17:10:09Z")

</div>

Hi Davida,

In your code detecting the projectile’s collision with the asteroid, it looks like there may be a mix-up between `sprite`, `otherSprite`, and `asteroid`. Here’s the current code:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/9/96545a1a3e59b492d7e426b19b6eec80cc0ab6da.png)

In this event, `sprite` is the sprite of kind Enemy (in other words, the asteroid) and `otherSprite` is the projectile. `Asteroid` is a variable you created earlier, which will likely be set to the last Asteroid you spawned, but is not necessarily the asteroid in the collision.

This code destroys `sprite`, which is the asteroid in the collision. I’m guessing you actually want to destroy `otherSprite`, which is the projectile. The code then tries to change the status bar on `Asteroid`, which may or may not be the asteroid you just destroyed (that would cause the issue you’re seeing). Instead of this, I expect you want to change the status bar on `sprite` (the asteroid actually involved in the collision).

In other words, something like this:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/2/2894c00bc1111c82d75b5105b021c203aaa96c38.png)

Does that resolve the issue you’re seeing?

---

<div class="post-metadata">

**Author:** ![Davida](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@Davida](https://forum.makecode.com/u/Davida)\
**Post date:** [March 27, 2024, 11:25pm UTC](https://forum.makecode.com/t/i-need-help-with-health-bars/27960/9 "2024-03-27T23:25:49Z")

</div>

Thank you, this very much resolves the issue.

---

<div class="post-metadata">

**Author:** ![Sparks](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sparks/32/8161_2.png) [@Sparks](https://forum.makecode.com/u/Sparks)\
**Post date:** [March 27, 2024, 11:27pm UTC](https://forum.makecode.com/t/i-need-help-with-health-bars/27960/10 "2024-03-27T23:27:20Z")

</div>

Glad to hear it 🙂
