✓ Accepted answer
This is called interpolating (smoothly moving between two options).
We first generate both results, and then figure out how far in time we are between the two. If we're 80% through the transitioning time, we figure out a way to be 80% towards the second color.
The simplest way to interpolate is called linear interpolation. It's called linear since the rate is constant through the transition, so the graph of any of the values is a line.
If we use ROBLOX's Vector3s to store the colors, it becomes a little briefer to do the math, so that's what I'll do.
begin = Vector3.new(math.random(),math.random(),math.random())
finish = Vector3.new(math.random(),math.random(),math.random())
startTime = tick()
duration = 5
while tick() - startTime < duration do
local progress = (tick() - startTime) / duration
local intermediate = finish * progress + ( 1 - progress ) * begin
local color = Color3.new(intermediate.x, intermediate.y, intermediate.z)
wait()
end
To make this loop, we just have to make a new finish but move finish into begin:
begin, finish = finish, Vector3.new(math.random(),math.random(),math.random())
2 comments
You can use Color3 Objects directly, since you can access the components as c3.r, c3.g, and c3.b. Directly equivalent to v3.x, v3.y, v3.z
Yes, but you lose the ability to use + and *, meaning the math becomes 3 times longer than necessary.