I'm wanting to know if it's possible to make this change colors as you have less and less health. Full health = Neon Green 75 Health = Yellow green 65 Health = Yellow 50 Health = Orange 24 And below = Red
local PositionX = script.Parent.Position.X.Offset local initX = script.Parent.Size.X.Offset while true do wait() local PlayerHealth = script.Parent.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.Health local PlayerMaxHealth = script.Parent.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.MaxHealth local Pie = (PlayerHealth / PlayerMaxHealth) script.Parent.Size = UDim2.new( 0, initX*Pie, 0, 20) end
Here you go!
Player = script.Parent.Parent.Parent.Parent.Parent.Parent Character = Player.Character Human = Character.Humanoid GUI = script.Parent --Remember to change this! If the script is inside of the thing you wanna color then leave it alone. function Check() --Using a function, I can connect this to the Changed event so I can change the color whenever the health is changed as opposed to a while loop if Human.Health == 100 then GUI.BackgroundColor3 = Color3.new(0, 1, 0) elseif Human.Health <= 99 and Human.Health > 65 then GUI.BackgroundColor3 = Color3.new(0.8, 1, 0) elseif Human.Health <= 65 and Human.Health > 50 then --Using this creates a range so it's not 1 color always GUI.BackgroundColor3 = Color3.new(1, 1, 0) elseif Human.Health <= 50 and Human.Health > 24 then GUI.BackgroundColor3 = Color3.new(1, 0.4, 0) elseif Human.Health <24 then GUI.BackgroundColor3 = Color3.new(1, 0, 0) end end Human.Changed:connect(function (property) if property == Health then Check() end end)
if PlayerHealth > 75 then script.Parent.Color = Color3.new(0,1,0) elseif PlayerHealth < 75 then script.Parent.Color = Color3.new(.8,1,0) elseif PlayerHealth < 65 script.Parent.Color = Color3.new(1,1,0) elseif PlayerHealth < 50 script.Parent.Color = Color3.new(1,.5,0) elseif PlayerHealth < 25 script.Parent.Color = Color3.new(1,0,0) end