Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How Do I Make This Color-Shifting Health Gui Show A Bit More Yellow?

I have a custom GUI that displays a player's health via a bar. As the player's health is damaged, the bar is supposed to gradually change colors from green to red. However, when the bar reaches halfway, I want the bar to show a much brighter yellow. With this script. the bar is only a brownish yellow at the halfway point. How can I accomplish this?

This is my script:

while wait(.1) do
	local player = game.Players.LocalPlayer
	local human = player.Character.Humanoid
	local health = human.Health
	local maxHealth = human.MaxHealth
	local ratio = health/maxHealth
	script.Parent.BackgroundColor3 = Color3.new(1-ratio, ratio, 0)
end

Any help is appreciated!

1 answer

Well, in order to create a very bright yellow, you need high values in Red and Green. So, at some point, both need to be high. You could separate the transition in two:

In the first half, you change green to yellow, by going from Color3.new(0, 1, 0) to Color3.new(1, 1, 0).

After 0.5 ratio, you change yellow to red, by going from Color3.new(1, 1, 0) to Color3.new(1, 0, 0).

Just have to do some maths to use the ratio value in that.

Also, HealthChanged event would be better than a while loop.

This discussion is preserved as it was. New answers, comments, and votes are closed.