Restore Health

Taking damage is common in games. How do we use the same principles to allow a player to heal?

Making a + Health icon

Using your building skills, create a + symbol with two parts. Make it green, glass, semi-transparent and anchored.


Particle Emitter

Health is a good thing so many games make it look magical. You will right click the Health Power Up in the Explorer and add a Particle Emitter. You can make it your own but these are the settings I used.

Coding the Spin

Create a child Script in the Heal object. Name it Animate. This code will make the pick up spin.

This uses a While and For Loop.  While 1 is 1 (which is always) you do the what it says. This is like the Forever loop on Scratch.

A For loop has three numbers- the starting number, the end number, and the number you count by. So it goes like this 0, 5, 10, 15 all the way to 180. We did 180 because that is a half turn. “wait()” is the time between each count, which is basically zero. If you increase the wait(#), it will spin slower.

Healing Script

Create a second script in the part. Name it Healing. Write this code. The comments are just for you to understand things.

Now to test it! Copy the Healing item. Make one of the codes SUBTRACT health by doing “hum.Health – HealAmount” and leave the other as it is. Unfortunately, trying to change Humanoid.Health in Properties during the game will not work.