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

How to fade through color3 values?

I'm not sure how to loop through color3 values. I want it to fade from green all the way back to green. I've achieved this in the past, but once again forgot what to do.

This is what I tried.

for i = 1,255 do
something.BackgroundColor = Color3.new(0, i, 0)
end

I know that it just goes up from black to green, but I don't even know where to start for that.

1 comment

1

You should check TweenService in Roblox API, it allows you to tween Color3 values.

2 answers

I am not sure how you want this to function but you might be better off using HSV.

This is a quick example of HSV a loop in a frame.

local runServ = game:GetService('RunService')

local frame = script.Parent

while true do
	for i=0, 1, 0.001 do -- loop through hue range
		frame.BackgroundColor3 = Color3.fromHSV(i, 0.5, 0.5)
		runServ.RenderStepped:Wait()
	end
end

If you are looking for a differnt type of colour loop then you might be better off using the tween service or using the lerp function of the color3 roblox data type.

I hope this helps. please comment if you have any other questions.

1 comment

0

I'll send a link of what I mean. This is my friend's channel and look at the background that has the fading colors. https://www.youtube.com/watch?v=-i_YHaVyofs

I would suggest looking into the TweenService if you're going to do more complex fading later but as for your script the problem is that the Color3 value expects a value from 0 to 1, This is your script but fixed:

for i = 1,255 do
	something.BackgroundColor = Color3.new(0, i/255, 0)
end

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