Sign in
Home
Online Classes
Instructors
Tutorials
☰
Register
Sign in
Online Classes
Instructors
Tutorials
1. Open Roblox studio and load the starter kit
2. Test it out
3. Group Activity: Parent and Child Sizes
4. Create a health bar container
5. Create the health bar
6. Create a local script
7. Access the player and health bar UI
8. Write a function to update the health bar
9. Test and adjust
10. Polishing the health bar effect
11. (Optional) Turn off the default GUI
12. (Optional) Push the visual design
Project 566: Custom Health Bar
9. Test and adjust
Test out how the health bar is working now. Does anything seem strange about it?
This challenge doesn't have a starting point
Hint: show steps
Steps
1. Why is the health bar super long?
Hint: show details
The health bar is super long because we set the X Scale of the health bar to be equal to the player’s current health.
When the game starts, the player health is at 100 - which means the health bar is size 100.
The biggest the health bar should ever be, to make sure it matches the parent scale, is just 1!
Let’s say the player loses some health, and now only has 75 points of health. The health bar would still be size 75, which is enormous.
We’ll need to make the health bar a decimal. The next step will show you how.
Hint: show image
2. Create an equation for a different health variable
Hint: show details
How would you turn the number 100 into the number 1? Or the number 75 into the number .75?
You could divide the first number by 100 to get it to be a decimal.
In the case of our code, we’d want to divide the player’s actual health by the player’s max health (which is 100.)
So if the player has full health, 100 divided by 100 becomes 1. If the player has 75 health, 75 divided by 100 becomes .75
Put this inside the HealthUpdate function.
humanoid.Health/humanoid.MaxHealth
Hint: show image
Hint: show code
3. Initialize the new health variable
Hint: show details
To keep track of this new decimal number, we’ll make it a variable. We can call it “currentHealth” or “decimalHealth” or something else that makes sense to you.
local currentHealth = humanoid.Health/humanoid.MaxHealth
Hint: show image
Hint: show code
4. Use the new health variable
Hint: show details
Go back into your UDim2 coordinate. What parameter would you want to replace with your new health variable?
healthBar.Size = UDim2.new(currentHealth, 0, 1, 0)
Hint: show image
Hint: show code
5. Test again!
Hint: show details
Test this again and your health bar should be working as expected!
×
×
Provide your email address for immediate project access
Email
Check your email for instructions on how to create a full DA account