Hello!
I have been digging my head for a while now, trying to find the formula to change the color of a health bar depending of the humanoid's health.
I want to change the Color3 depending of the health.
Let me show you what I've done so far :
Let's say the variable hp is the Health, and mh is the MaxHealth.
First, I'm working on the first half (100% to 50% health), changing the color from green to yellow.
local hp = script.Parent.Humanoid.Health
local mh = script.Parent.Humanoid.MaxHealth
local bar = script.Parent.BillboardGUI.ImageLabel.Frame
while wait(0.2) do
if hp > mh/2 then
bar.BackgroundColor3 = Color3.new(hp/(mh/2),1,0)
end
end
The issue with this is, when the health bar is full, the color is greenish-yellow, kind of like goo. What I'm striving for is a "healthy" green color. I tried to fix this by adding a -0.5,
bar.BackgroundColor3 = Color3.new(hp/(mh/2)-0.5,1,0)
But then, when it reaches half, it gets to the goo color and not the "New Yeller" color. To recap, my question is : What is the formula I should use to change the color smoothly from 100% to 50%?
Oh, and if you have the time and patience, please, can you do the same for yellow to red? I tried my (awful) formula by inverting all numbers (positive to negative) but then it goes to red and yellow. I'm awfully confused, please help! Thanks. **

2 comments
You can simplify this code a lot.
just use the :Lerp function bruh