How to make Colours change smoothly?

Hello, im very new to scripting, i made this simple script, and i would like to know how to make colours change smoothly.

local part = game.Workspace.Part

while true do

part.Color = Color3.fromRGB(255, 0, 0)
wait(0.1)
part.Color = Color3.fromRGB(255, 102, 0)
wait(0.1)
part.Color = Color3.fromRGB(255, 204, 1)
wait(0.1)
part.Color = Color3.fromRGB(102, 255, 0)
wait(0.1)
part.Color = Color3.fromRGB(0, 243, 255)
wait(0.1)
part.Color = Color3.fromRGB(42, 0, 255)
wait(0.1)
part.Color = Color3.fromRGB(128, 0, 255)
wait(0.1)
part.Color = Color3.fromRGB(255, 1, 166)
wait(0.1)
	
	end

you can use tween service with that, more info here TweenService | Roblox Creator Documentation

1 Like

he’s right, tweens allow for smooth transitions / changes in properties
here is a rainbow tween for example;

TS = game:GetService("TweenService") -- Since tweens are a service, you'll need to get them with this.
Part = Workspace.Part -- Part you want the effect to apply on
TI = TweenInfo.new(5,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0)
 -- (NumberTime,EasingStyle,EasingDirection,RepeatCount,Boolreverses,Delay time)
-- NumberTime is how long you want the tween to last in seconds (s)
--EasingStyle is the style of the tween, they can come in multiple forms such as Quad, Bounce, Linear etc.
--Easing Direction is the direction of when you want easing to apply, for example, setting it to InOut will make it easy at the start and end of the tween.
--Repeat count is the amount of times you want the tween to repeat **Do not use this if you're putting the tween in a loop.** if you want to repeat it forever, just put it inside a loop like below.
--BoolReverses is something i don't know. i think it's the amount of times you want the tween to reverse itself (so instead of Col1,2,3, it'll do Col 3,2,1 after 1,2,3 was done)
--DelayTime is how long you want to delay the tween from begining in seconds (s) (for example, putting 1 would make the tween wait 1 second before playing.)
Col1 = [Color = Color3.FromRGB(255,0,0)] -- these are the properties you want to change, they must be closed in [], NOT (). some properties will also not work with tweens.
Col2 = [Color = Color3.FromRGB(0,255,0)]
Col3 = [Color = Color3.FromRGB(0,0,255)]

T1 = TS:Create(Part,TI,Col1) -- (Part,TweenInformation,The Property you want to change)
T2 = TS:Create(Part,TI,Col2)
T3 = TS:Create(Part,TI,Col3)

While true do
wait()
T1:Play()
wait(5) -- how long the tween was from tween info
T2:Play()
wait(5)
T3:Play()
wait(5)
end
1 Like
local part = game.Workspace.Part

while task.wait() do
	local partR = part.Color3.fromRGB.R
	local partG = part.Color3.fromRGB.G
	local partB = part.Color3.fromRGB.B
	local rand1 = math.random(1, 2)
	if rand1 == 1 then
		part.Color = Color3.fromRGB(partR * 1.01, partG * 1.01, partB * 1.01)
	elseif rand1 == 2 then
		part.Color = Color3.fromRGB(partR * 0.99, partG * 0.99, partB * 0.99)
	end
end

use TweenService!

local Colors={
{Color=Color3.fromRGB(255, 0, 0),Time=.1},
{Color=Color3.fromRGB(255, 102, 0),Time=.1},
{Color=Color3.fromRGB(255, 204, 1),Time=.1},
{Color=Color3.fromRGB(102, 255, 0),Time=.1},
{Color=Color3.fromRGB(0, 243, 255),Time=.1},
{Color=Color3.fromRGB(42, 0, 255),Time=.1},
{Color=Color3.fromRGB(128, 0, 255),Time=.1},
{Color=Color3.fromRGB(255, 1, 166),Time=.1},
}
local EasingStyle=Enum.EasingStyle.Sine
local EasingDir=Enum.EasingDirection.In

local part=Instance.new("Part",workspace)
local TweenService=game:GetService("TweenService")
while task.wait() do 
    for i=1,#Colors do 
    local cur=Colors[i]
	local Data = TweenInfo.new(cur.Time,EasingStyle,EasingDirection,0,false,0)
	local tween = TweenService:Create(Part,Data,[Color=cur.Color]) 
	tween:Play()
	repeat task.wait() until tween.Completed 
	end 
end 

change the content inside the Colors table to suit your needs Time control how much time until it changes to the next color, you can add as much as you want!
i made it .1 secs because thats originall whats on your script but imo its too fast…
You can also change the easing style and direction with the variables i provided.