Help with coding sorry for spelling

First, your current code sets the life back up to 3 every time the “enemy overlapped player” code runs. To change that, I’ll move the set life block to the On Start:

Now, when we hit an enemy, our health goes down, but we instantly die. This is because every frame the you are touching the enemy, -1 health is applied, and at even 30 frames per second it takes just a 10th of a second to lose all 3 lives.
To fix this, most games either destroy the enemy when it touches you the first time (for example a bullet damages the player once and then gets destroyed) or you give the player a short time where they are invincible, called i-frames. To do this, we can create a variable that starts a countdown when the player gets hit, and then the player can’t get hit again until that countdown is over:

If it’s hard to understand what those variables are doing, here is a version that might be easier to understand:

Hope this helps! And welcome to the Makecode forums! If you have any more questions don’t hesitate to ask!

1 Like