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

How could I stop my Color3 Lerp?

I'm lerping the color property of a PointLight to make it blue, it worked until I added my while loop. How could I successfully stop the b value of a Color3 from going over 255? Any and all help is welcome.

wait(5)
function LerptoBlue()
	for i = 0,1,0.000015 do
		script.Parent.PointLight.Color = script.Parent.PointLight.Color:lerp(Color3.new(0,0,255), i)
		wait()
			while true do
			if
				script.Parent.PointLight.Color.b > 255 then
				script.Parent.PointLight.Color.b = 255
			end
			wait(1)
		end
	end
end

LerptoBlue()

5 comments

0

It might be because your "for" loop won't ever be one. Because if you were to times 0.000015 to get 1, you'd get an odd number (66666.6667)

0

No. I think lerping accounts for this.

0

Just remove the while and the wait in the while. I see no point in it

0

Try doing "/255" after each color3 number. So "0/255,0/255,255/255"

0

Color3 values can't go over 255 (or 1).

1 answer

✓ Accepted answer

I too myself recently found out that doing 0,0,255 is a RGB (Red Green Blue), and to transform this to Color3, we simply add a /255 after it!

wait(5)
function LerptoBlue()
    for i = 0,1,0.000010 do
        script.Parent.PointLight.Color = script.Parent.PointLight.Color:lerp(Color3.new(0/255,0/255,255/255), i)
        wait()
    end
end

LerptoBlue()

I also went ahead and removed that useless while loop.

1 comment

0

You can use Color3.fromRGB instead of Color3.new(0/255, 0/255, 255/255). You can also do Color3.new(0, 0, 1)

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