Change the Hue of a color

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I would like to be able to change the HUE of the GUI, without touching the other values

  2. What is the issue? Include screenshots / videos if possible!
    It first changes the color to random ones, then stop changing them after a few scroll.

I added the D variable cause i thought i was scrolling too fast, but that wasn’t the issue.

--Variables
local Main = script.Parent.Main
local Rainbow = script.Parent.Rainbow.ScrollingFrame

local D = false

--Rainbow Moved
Rainbow:GetPropertyChangedSignal("CanvasPosition"):Connect(function()
	if D == false then
		D = true
		local Code = Rainbow.CanvasPosition.Y/252734
		local Color = Main.BackgroundColor3
		

		Main.BackgroundColor3 = Color3.fromHSV(359*Code, Color.G, Color.B)
		
		wait(0.3)
		D = false
		
	end
	
end)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Tried searching around, found nothing

You’re using the Green and Blue components of the existing color as Saturation and Value.
You can use Color3.ToHSV() to get Saturation and Value of the existing color.

1 Like

I thought it was supposed to be a value between 0 and 1.

1 Like

how does it work then?
In the color menu the maximium number for the HUE it’s 359.

Fixed the code, now it works!

--Variables
local Main = script.Parent.Main
local Rainbow = script.Parent.Rainbow.ScrollingFrame

local D = false

--Rainbow Moved
Rainbow:GetPropertyChangedSignal("CanvasPosition"):Connect(function()
	
	local Code = Rainbow.CanvasPosition.Y/252734
	local Color = Main.BackgroundColor3
	
	Main.BackgroundColor3 = Color3.fromHSV(Code, 1,1)
	
end)

Thanks to everyone for the help

Check the documentation for Color3.fromHSV()

fromHSV

Creates a Color3 with the given hue, saturation, and value. The parameters should be in the range [0, 1].

Parameters

hue: number

saturation: number

value: number

To set the hue of a Color3 you can use Color3.fromHSV(<hue>, 1, 1) where <hue> is a number between 0 and 1.
To get the current hue you can use Color3.ToHSV().

E.g.

local function shiftHue(color: Color3, hueShift: number): Color3
	local hue, saturation, value	= color:ToHSV()	-- get current hue
	hue	= hue + hueShift	-- change hue by hueShift amount
	hue	= hue % 1			-- make sure value rolls over >1 to stay within 0-1
	return Color3.fromHSV(hue, saturation, value)	-- return Color3 with new hue
end

local color		= Color3.fromHSV(0, 1, 1) -- create starting color
local hueShift	= 0.05 -- you can use any value between 0-1

color = shiftHue(color, hueShift) -- shift hue of color

If you don’t understand this I highly recommend reading the documentation for both Lua and the specific Roblox objects you’re trying to use.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.