Tweening ColorHSV Tweens really fast

I want to make a rainbow part, but when I use tweenservice, even if the time is slow, it tweens strangely, I would expect it to go smoothly between hue 0 and hue 359. But instead it does this:

local Lazer=Instance.new("Part",Character)
Lazer.Name="Lazer"
Lazer.Shape=Enum.PartType.Cylinder
Lazer.CanCollide=false
Lazer.CFrame=Character["Left Arm"].CFrame*CFrame.new(0,-1,0)*CFrame.Angles(0,0,math.rad(90))
Lazer.TopSurface=Enum.SurfaceType.Smooth
Lazer.BottomSurface=Enum.SurfaceType.Smooth
Lazer.Anchored=true
Lazer.Size=Vector3.new(0,0.5,0.5)

local colortween=TS:Create(Lazer,TweenInfo.new(1000000,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0),
	{["Color"]=Color3.fromHSV(359,255,255)}
)

Lazer.Color=Color3.fromHSV(0,255,255)
colortween:Play()

I looked into it and it appears that it is tweening the color one by one, as if

for r=1,255 do
	for g=1,255 do
		for b=1,255 do
			Lazer.Color=Color3.fromRGB(r,g,b)
		end
	end
end

I want to tween the hue of HSV as I believe that will give a very nice transition between colors.

Why is the tween tweening like this? And is their any way to fix this?

2 Likes

It might have to do with the unreasonably high time that it is set to take.
Your tween time is 1,000,000 seconds, or 11.5 DAYS. Try reducing that to something MUCH smaller and see if it helps

Edit: also, as the person below said, fromHSV accepts 3 values between 0 and 1, not 360, 255, 255.

2 Likes

I think it’s partially because Color3.fromHSV accepts values in the range [0,1]

1 Like

I increased the time it takes so much as without a reasonable time, such as 1, the color changing was so fast, it was seizure inducing.
The reason I thought it took 360,255,255, was because clicking on the color wheel next to the preview color opened up the select color menu, and that uses 360 for hue, 255 for saturation, and 255 for value (brightness)

A mistake I’m sure many have made! Color3.new and Color3.fromHSV and things require 0-1, because that’s just how it likes things

Tada!

Or basically:

local Lazer=Instance.new("Part",Character)
Lazer.Name="Lazer"
Lazer.Shape=Enum.PartType.Cylinder
Lazer.CanCollide=false
Lazer.CFrame=Character["Left Arm"].CFrame*CFrame.new(0,-1,0)*CFrame.Angles(0,0,math.rad(90))
Lazer.TopSurface=Enum.SurfaceType.Smooth
Lazer.BottomSurface=Enum.SurfaceType.Smooth
Lazer.Anchored=true
Lazer.Size=Vector3.new(0,0.5,0.5)

local value = Instance.new("NumberValue")

local colortween=TS:Create(value,TweenInfo.new(10,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0),
	{Value = 1}
)
colortween:Play()
value.Changed:Connect(function()
	Lazer.Color = Color3.fromHSV(value.Value,1,1)
end)
colortween.Completed:Connect(function()
	value:Destroy()
end)

I found that tweening the hue resulted in a strange dark, muddy yellow, not at all pleasant to look at, so I will use this Variation,

task.spawn(function()
	while true do
		for i = 0,1,0.01 do
			Lazer.Color = Color3.fromHSV(i,1,1)
			wait()
		end
	end
end)

I found this one too look nice. Thank you for all the resources and knowledge on how this works. Thank you all.

EDIT: there was a bug in my code, did while wait() do

You are welcome but if I may, what solved the issue? My code or your’s?

Your code worked, I just felt the usage of .Changed() and a tween was strange and struck me as off, But your link contained the code example that I used, so I say you provided the solution.

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