Tutorial:Making a Heal Pad

In this tutorial, we will go over making a simple heal pad. This tutorial is scripting, not building. This script assumes you already have something set up as so:

If you do not, please create something identical to this. You can name it whatever, as the name does not matter.

Lets get into the scripting portion. We are going to start by making a Touched event. The code inside of this function will now be ran whenever the part is touched. But we can't just heal the player. How do we even know it is a player? If it turns out the part was just the floor, the script would break. We need to add an if statement to determine if it is a player. We do this by adding this statement: This if statement checks to see if the hit has a in it's parent. But why in its parent, not its self? Simple. The 'hit', if it is a player's character, is one of the limbs, not the model. Now that we got the if statement, lets heal the player. This code sets the 's health to it's maximum health, essentially healing them to. Simple as this.

The previous script allowed the player to heal to 100% of its health, but what if we only want to heal them a little bit? Well, we use the same code as before, only instead of setting the player's health to a fixed amount, we ADD to the current health.

Every time the player touches the part now, it will add 10% of the player's maximum health. I put the * symbol before the + sign to prevent any confusion with order of operations.

One last problem, though: the function fires too many times! We only want it to fire once, then start a cooldown. To do this, we use debounce. Here, the function will fire once, then wait 5 seconds before it can fire again.