I’m trying to make my own health Gui that changes whenever the player is damaged. I want to add a color scale though depending on the value of the players health. The only issue is, I don’t want to manually type out the values for the colors of the health bar, so I was wondering what you think I should do.
I want it to be a high green when full, and red when zero.
local green = Color3.new(0, 1, 0)
local red = Color3.new(1, 0, 0)
-- `PLAYER_HEALTH` and `MAX_HEALTH` are self-explanatory, but those are the
-- the player's current and maximum health respectively
local healthLerpTime = PLAYER_HEALTH / MAX_HEALTH
-- this will return a value betwen 0 and 1. This is the alpha time to determine how far
-- the value will be along until it reaches the end point.
-- for example, if `healthLerpTime` is 0.5, that would return a color that's half-way between green and red (orange)
local healthColor = red:Lerp(green, healthLerpTime)
-- if the player has full health, it will appear green, if they don't, it will appear red