Error Cannot read properties of undefined (reading ‘fields’)

Español:
Estaba Creando un proyecto de makecode arcade y al ganar el juego me aparecia el error y luego
al presionar el menú también se rompía. Les comparto el proyecto para que por favor lo
solucionen.
https://makecode.com/_A7mKHjce17sR](https://makecode.com/_A7mKHjce17sR)
English:
I was creating a Makecode arcade project, and when I won the game, I got the error, and then pressing the menu also crashed. I’m sharing the project with you so you can please fix it.
https://makecode.com/_A7mKHjce17sR](https://makecode.com/_A7mKHjce17sR)

1 Like

Welcome to the Makecode Forum!
Your main problem was these:


When you win, or click Menu, the game changes “scene” and everything disappears. That means your sprites also stop existing. Usually Forever blocks stop running when this happens, but those While blocks keep running, and because the sprite doesn’t exist anymore, it causes an error. To fix this, I turned your While blocks into If blocks. This didn’t work, because your code doesn’t work in IF blocks, so I changed it so that it works. Then I realized that since all your ghosts are “Enemy” type, I could make a loop that ran the code for all of them:

Now it all works correctly and doesn’t break when you click Menu!
Here is my version of your project: