I am trying to script a color changing smoke but it either rapidly changes, goes over 255 or under 0 and then doesn't change back, is there any way to make it so it smoothly changes color without it flashing or going over 255 or under 0? This is the script I was using:
number1 = math.random() number2 = math.random() number3 = math.random() while wait() do script.Parent.Smoke1.Smoke.Color = Color3.new(number1,number2,number3) script.Parent.Smoke2.Smoke.Color = Color3.new(number1,number2,number3) number1 = math.random() number2 = math.random() number3 = math.random() end
Is there any way to make it kind of fade to random colors or is this the best I can do?
You have to make a Color3 Tweener. This is a difficult concept to explain but I want to give you code so you can study it because I don't wanna leave you empty handed.
Basically what you have to do is get the current color, and the wanted color. Then find the difference in individual RGB values betwixt the two, and gradually change the color according to the differences.
function TweenColor3(Color1, Color2, Output, Time, Smoothness) --Find the difference between the current color and the next color local Difference = { R = Color2.r - Color1.r, --Red difference G = Color2.g - Color1.g, --Green difference B = Color2.b - Color1.b --Blue difference } --Gradually change color according to the difference for i = 1, Time * Smoothness do Output = Color3.new( Output.r + Difference.R * (Time / Smoothness), Output.g + Difference.G * (Time / Smoothness), Output.b + Difference.B * (Time / Smoothness) ) wait() end end --[[ Usage; local Color = Color3.new(255,0,0) local wantedColor = Color3.new(0,255,0) local outputColor = Color3.new() local Time = 6 TweenColor3(Color,wantedColor,outputColor,Time,15) ]]
function TweenColor3(Color1, Color2, Output, Time, Smoothness) local Difference = { R = Color2.r - Color1.r, G = Color2.g - Color1.g, B = Color2.b - Color1.b } for i = 1, Time * Smoothness do Output = Color3.new( Output.r + Difference.R * (Time / Smoothness), Output.g + Difference.G * (Time / Smoothness), Output.b + Difference.B * (Time / Smoothness) ) wait() end end --[[ Usage; local output = script.Parent.Smoke.Smoke1.Smoke local a = math.random --make it shorter haha local wantedColor = Color3.new(a(0,255)/255,a(0,255)/255,a(0,255)/255) local Time = 6 TweenColor3(output.Color,wantedColor,output,Time,15) ]]