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

Color3 Becoming Way Off?

Hi. I'm making a Health GUI, with a script that makes the Text Color change whenever the health changes. The code works, but when I try to change the Color3 of the TextLabel, it goes to ridiculously large numbers. The output prints it out how it should be, but the TextLabel just seems to turn it into a different number. Can somebody help, please? Here's the code I'm working with.

function findColor(healthNum)
	local newg = healthNum * 2.55
	local newr = 255 - newg
	return Color3.new(round(newr), round(newg), round(b))
end

game.Players.LocalPlayer.Character.Humanoid.Changed:connect(function(property)
	if property ~= "Health" then return end
	local char = player.Character
	local human = player.Character.Humanoid
	if human == nil then return end
	local newTextColor = determineColor3(human.Health)
	script.Parent.Health_Text.TextColor3 = newTextColor
	print(tostring(newTextColor)) -- this results in numbers below/equal to 255, but the color itself is in 
	-- the ten thousands
end)

1 comment

0

Also, the rounding function is predefined earlier, it's simply made to round the numbers if they are a large decimal.

1 answer

✓ Accepted answer

Color3 uses floats, which means you need to divide the numbers by 255

function findColor(healthNum)
    local newg = healthNum * 2.55
    local newr = 255 - newg
    return Color3.new(round(newr)/255, round(newg)/255, round(b)/255)
end

Why?
RGB values are wonderful to represent in values up to 255 because it makes sense when they're stored in a byte. Unfortunately, it doesn't make the same amount of sense in terms of colour theory.

1 comment

0

Thanks! Still don't completely understand it, but I'll look into it. The code is fine, though.

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