Health bar problem - damage doesnt coloring properly

code

Character.Humanoid.HealthChanged:Connect(function()
			healthbar.Bar.Size = UDim2.new(1/(Character.Humanoid.MaxHealth/Character.Humanoid.Health),0,1,0)
			healthbar.Bar.BackgroundColor3 = Color3.fromRGB(-255-Character.Humanoid.MaxHealth/Character.Humanoid.Health,255-Character.Humanoid.MaxHealth/Character.Humanoid.Health,0)
		end)

problem is when player damaging he just getting yellow bar not green when fully healed or red when near death just yellow (i experemented and got even worse)(im bad at math ;c )
please help

Try this: make a function that determines the humanoid’s health and then run that function to determine what colour the health bar should be.

thats probably gonna be useless

Character.Humanoid.HealthChanged:Connect(function()
	
	healthbar.Bar.Size = UDim2.new(Character.Humanoid.Health / Character.Humanoid.MaxHealth, 0, 1, 0)
	
	healthbar.Bar.BackgroundColor3 = Color3.fromRGB(
		255 * (Character.Humanoid.Health / Character.Humanoid.MaxHealth),
		255 * (1 - (Character.Humanoid.MaxHealth/Character.Humanoid.Health)),
		0
	)
	
end)

i just found thats

Color3.new(-1*Character.Humanoid.Health/Character.Humanoid.MaxHealth,Character.Humanoid.Health/Character.Humanoid.MaxHealth,0)

does the job but when its half of health yellow color just dirt color