I made a custom hp bar, And the color supposed to be between red and green but the color keeps going to numbers like 69000 what is going on???
x = 314 y = 40 game.Players.PlayerAdded:Connect(function(plr) --//values\\ local gui = plr.PlayerGui:WaitForChild("Health", 99) local hbar = gui:WaitForChild("Bar", 99) local playerhp = gui:WaitForChild("PlayerHealth", 99) local maxhealth = gui:WaitForChild("MaxHealth", 99) local persec = gui:WaitForChild("PerSecond", 99) local percent = playerhp.Value / maxhealth.Value --//connect\\ playerhp.Changed:connect(function() playerhp = gui:WaitForChild("PlayerHealth", 99) maxhealth = gui:WaitForChild("MaxHealth", 99) persec = gui:WaitForChild("PerSecond", 99) percent = playerhp.Value / maxhealth.Value --//color\\ local green = 255 * playerhp local red = 255 - green hbar.BackgroundColor3 = Color3.new(red,green,0) --//size\\ hbar.Size = UDim2.new(0,(playerhp.Value / maxhealth.Value) * x,0,y) end) --//end connect\\ end)
please help!
Because Color3.new accepts numbers from 0 - 1 and you're passing higher numbers.
local green = percent local red = 1 - percent hbar.BackgroundColor3 = Color3.new(red, green, 0)