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

The numbers getting crazy How do I fix it?

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!

1 comment

0

playerhp is an objectvalue? and your equation is wrong, it should be: local green = 1 * percent

1 answer

✓ Accepted answer

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)

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