I do not suggest to use tween for this, instead let’s use
Color3.fromHSV(.3, 1, 1) -- green
and let’s slowly move it to:
Color3.fromHSV(0, 1, 1) -- red
So first we want to know the amount of health left in decimals so lets do:
local Progress = Health/MaxHealth
This will result into a value for 1 if full health and 0 if you are dead.
Now if the value is 1 we want the Hue
(H) to be equal 0.3
, but if it’s 0
we want it to be equal to 0
, which is quite easy:
HealthBar.BackgroundColor3 = Color3.fromHSV(0.3 * Progress , 1, 1)
Note, this will slow the color yellow and orange as well, because basically what it does, it scrolls the Hue
from left to right: