Color3 Values inverting

Hello, I am experiencing an issue where the Color3 values are inverting for me when I return them from a function. Here is the script.

local function c3(hex)      -- from https://gist.github.com/jasonbradley/4357406
	hex = hex:gsub("#","")
	local r, g, b = tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6))
	return Color3.new(r,g,b)
end

Confirm.MouseButton1Click:Connect(function()
	print(c3(Hex.Value.Text))
	
	FlareColorEvent:FireServer(c3(Hex.Value.Text))
	script.Parent:Destroy()
end)

event.OnServerEvent:Connect(function(plr,Color)
	print(plr)
	print(Color)
	script.Parent.Handle.Part.Color = Color
	script.Parent.Handle.Part.PointLight.Color =  Color
	script.Parent.Handle.Part.Smoke.Color = Color
end)

On the print(Color) line, it prints the Color3 values the right way round, but when I change the color of the brick, the values are inverted.

The Color3.new constructor expects the r, g, and b arguments on the range [0, 1]. It looks like you might be feeding it numbers on the range [0, 255] in the c3 function. Possibly try the Color3.fromRGB constructor instead as the r, g, and b arguments for this constructor expect [0-255]. There is also a Color3.fromHex constructor which takes a string (ex. Color3.fromHex("#FF0000") would be red) and may remove the need for the c3 function for this use case. See Color3 for more information.

1 Like