# Cannot read property of null reading fields something something

**URL:** <https://forum.makecode.com/t/cannot-read-property-of-null-reading-fields-something-something/40692>\
**Category:** Help\
**Tags:** extension\
**Created:** [November 28, 2025, 4:01am UTC](https://forum.makecode.com/t/cannot-read-property-of-null-reading-fields-something-something/40692 "2025-11-28T04:01:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phosphophyllite](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/phosphophyllite/32/32491_2.png) [@phosphophyllite](https://forum.makecode.com/u/phosphophyllite)\
**Post date:** [November 28, 2025, 4:01am UTC](https://forum.makecode.com/t/cannot-read-property-of-null-reading-fields-something-something/40692/1 "2025-11-28T04:01:17Z")

</div>

Hello! I’m trying to make a game where enemies have individual health bars assigned to them, however I keep getting an error when I attempt to do so. The code is in the function ‘EnemySetUp’, does anybody know how to fix this?

> **[U5 PROJECT](https://arcade.makecode.com/S67968-98765-22672-48718)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![AnOminousWolf](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/anominouswolf/32/21874_2.png) [@AnOminousWolf](https://forum.makecode.com/u/AnOminousWolf)\
**Post date:** [November 28, 2025, 7:56pm UTC](https://forum.makecode.com/t/cannot-read-property-of-null-reading-fields-something-something/40692/2 "2025-11-28T19:56:05Z")

</div>

The code for the snake’s health bar assumes that a snake was created beforehand. However, in Level 2, a snake tile was never found, and so a snake was never created. So, it crashed because it couldn’t get the correct data from an empty variable.

> **[U5 PROJECT (Health bar fix)](https://arcade.makecode.com/S20009-40639-32602-34536)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

This adds an If statement checking if a snake exists before creating the snake health bars. However, I’d suggest instead is create the health bar inside of the same For loop that creates the snakes. That way, we don’t need to use somewhat odd javascript mechanics, and previous enemies don’t get a snake health bar. (More is in the comment of the added if statement!)  
Hope this helps 🙂

---

<div class="post-metadata">

**Author:** ![dogSquid](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dogsquid/32/26689_2.png) [@dogSquid](https://forum.makecode.com/u/dogSquid)\
**Post date:** [November 28, 2025, 7:58pm UTC](https://forum.makecode.com/t/cannot-read-property-of-null-reading-fields-something-something/40692/3 "2025-11-28T19:58:52Z")

</div>

> **[U5 PROJECT - fixed](https://arcade.makecode.com/81265-67440-35904-99308)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

I don’t exactly understand what the problem was, but I made 2 new kinds (Snake and Slime) and used these in the code instead. Now it seems to work!

---

<div class="post-metadata">

**Author:** ![phosphophyllite](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/phosphophyllite/32/32491_2.png) [@phosphophyllite](https://forum.makecode.com/u/phosphophyllite)\
**Post date:** [November 29, 2025, 4:32am UTC](https://forum.makecode.com/t/cannot-read-property-of-null-reading-fields-something-something/40692/4 "2025-11-29T04:32:55Z")

</div>

Thank you very much for your help! I’ll try putting the health bar in the for loop.
