Project 566: Custom Health Bar

7. Access the player and health bar UI

Create variables to keep track of the player, the player's humanoid object, and the health bar.  

You'll also add in a slight delay before referencing these things, in case the script activates before the character loads in!
Starting point file for this challenge

Steps

1. Tell the script to wait for 1 second before activating

This is just in case the game decides to load the script before it loads the character in. 
wait(1)

2. Create a local variable for the player

Creating a variable in Lua is as easy as typing in "local" and then the name of your variable. We'll call this variable "player" to stay organized. 
local player

3. Tell the script where the player variable is

When you load the game, Roblox will call your specific player the name "LocalPlayer" and will store that in a folder called "Players" 
game.Players.LocalPlayer

4. Create and initialize a variable for the player's Character object

Create a new variable called "character" and set it equal to the Character object, found inside your new "player" variable. 
local character = player.Character

5. Create and initialize a variable for the player's Humanoid object

Create a new variable called "humanoid" and set it equal to the Humanoid object, found inside your "player" variable. 
local humanoid = character.Humanoid

6. Create a variable to keep track of the health bar

We'll just create a local variable called "healthBar" 
local healthBar

7. Tell the script where the HealthBar object is

We have to connect the dots from the script to the health bar. 

We have to find the parent that both the Health Bar and Script share, which is the Container.

This line tells Roblox to find the script, go up a level to find the parent (Container) then go back down to find another child of the Container, the HealthBar. 

script.Parent.HealthBar