How to use HSV to form a colour sequence

I have a row made up of parts and Im trying to make a recurring colour sequence, one that kind of looks like a rainbow.
Here’s a picture :

What I have tried so far is iterating through the parts and adding a small amount of hue value to each part and when their hue value reaches max (1) it resets back to 0.

However this does not look smooth at all and the parts somehow end up having a very similar colour after a bit.

Here’s a picture of my code :

Note: The for loop is under a render stepped event.


Since color in computers is normally on a scale of 0-255, but Roblox measures colors from 0-1, the colors would be smoother if you added 1/255 instead of 0.1. Hope this makes sense

1 Like

Ill try, doubt this fixes the problem though.

1 Like

excuse me being an idiot above

local basePart = workspace:WaitForChild("Part")

for i = 1, 20 do
	-- create a row of parts
	local newPart = basePart:Clone()
	newPart.Color = Color3.fromHSV(i / 20, 1, 1)
	newPart.Position = basePart.Position + * i, 0, 0)
	newPart.Parent =
	-- same value as color above, 0-1

	local hValue ="NumberValue")
	hValue.Name = "hValue"
	hValue.Value = i / 20
	hValue.Parent = newPart

	-- just advance each color by deltaTime
	for i,v in pairs( do
		-- probably faster than converting RGB to HSV, i just did it because i don't like dealing with conversion
		local hComponent = v.hValue.Value + (deltaTime / 25)
		-- roll the value over when too high but *smoothly*
		if hComponent >= 1 then
			hComponent = hComponent - 1
		-- set the values
		v.Color = Color3.fromHSV(hComponent, 1, 1)
		v.hValue.Value = hComponent

Give the parts an individual value for Hue, and roll it over when required. Your error was most likely h = h + 0.1 and setting h to 0 instead of h - 1 when rolling it back under 1
edit: sorry if this is spoonfeeding, i tried to explain what little there was to explain using code comments


I’m assuming your issue isnt the color rather than the sequence not going in order. This is because a for loop won’t order them for you nor will a model or folder. I would use a numerical loop. and name the parts corresponding to their position in the sequence. Then you can index from the table made for the numerical loop the next part in the sequence.

Forgive me for not giving an example as I am on my smartphone.

1 Like

I’m not even sure if there is a ToHSV function, where did you know this?

1 Like

AFAIK you’ll have to implement it yourself if you want to convert it to HSV, this algoirthmn might help you:

Edit: As @TheTurtleMaster_2 said there’s ToHSV. (I’m thinking this in C#)

There exists ToHSV function, check this:


Hi my friend told me using ipairs takes the parts in order of creation/parenting. Ive tested this and it seemed to work but I will still consider your suggestion.

This worked well , Thanks a lot dude, however I do not completely get the use of deltatime as im not familiar with it.
Could you explain please?