Change BackgroundColor3 Dependent on a value

Kinda hard to explain, so i’ll try my best to tell what i want:

I Hope you can understand what i mean with this…

The Max HP of a player is 100%, and the minimum is obviously 0%
If the Player’s HP is at 100%, the Health bar would be green,
If the Player’s HP is at 0%, the Health bar would be red,
if the Player’s HP is at 50%, the Health bar would have a mixed color between green and red (Yellow)

Looks simple, but still can’t think how i would do this.

You could do this pretty simply with HSV values. Try something like this.

local fullHealthColor = 125;

function getHealthColor(health, maxHealth)
    return Color3.fromHSV((health/maxHealth)*fullHealthColor/360, 1, 1);
end
3 Likes