So I made a healthbar script that works fine with tweening the position of the bar, but it does not set the color properly, I think it is setting the color to the math it is doing? Code:
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Health,false)
local player = game.Players.LocalPlayer
local character = game.Workspace:WaitForChild(player.Name)
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local healthbar = script.Parent.remaining
function checkcolor(health,maxhealth)
print("calculating color")
if(health > (maxhealth/3)*2.5) then
print("setting color to green")
healthbar.BackgroundColor3 = Color3.new(0, 255, 119)
end
if (health <= (maxhealth/3)*2.5) then
print("setting color to yellow")
healthbar.BackgroundColor3 = Color3.new(255, 247, 14)
end
if (health <= (maxhealth/3)*2) then
print("setting color to orange")
healthbar.BackgroundColor3 = Color3.new(255, 144, 8)
end
if (health <= (maxhealth/3))then
print("setting color to red")
healthbar.BackgroundColor3 = Color3.new(255, 0, 0)
end
end
function HealthChanged()
local maxhealth = humanoid.MaxHealth -- for now
local health = humanoid.Health
script.Parent.Parent.healthoutof.Text = health.."/"..maxhealth
script.Parent.Parent.healthoutof.healthoutof.Text = health.."/"..maxhealth
checkcolor(health,maxhealth)
healthbar:TweenSize(UDim2.new(health/maxhealth,0,1,0),"In","Linear",0.1)
end
HealthChanged()
humanoid.HealthChanged:connect(HealthChanged)
So if I do something like setting the health to 80, it should set the color to orange, but instead it sets the color to Color3.new(65025, 62985, 3570)

1 comment
Alternatively you can use the new Color3 function Color3.fromRGB where you can have whole numbers.