How to make a part and gui have a smooth rainbow animation

This video shows what I mean but the code is kinda hard to understand

1 Like

It’s really simple for me I just tween the color property to a random color and wait until it’s completed.

local TweenService = game:GetService('TweenService')
local object = script.Parent
local tweenInfo = TweenInfo.new(2.5)

while true do
local r, g, b = math.random(), math.random(), math.random()
local goal = {Color = Color3.new(r, g, b)}

local tween = TweenService:Create(object, tweenInfo, goal)
tween:Play()
tween.Completed:Wait()
end

For guis change “Color” to “BackgroundColor3”.

6 Likes

ik but the tween have to first finish but i want it to change colors fast

Then change the first argument of the tween info.

Change it to TweenInfo.new(0.1)

How would I do it with a part would I use the color property

Yes, do local goal = {Color = Color3.new(r, g, b)}.

This is code for a color changing GUI that I made a while ago (it moves too):
local object = script.Parent

object.AnchorPoint = Vector2.new(0.5, 
0.5)

wait(2)

object:TweenPosition(UDim2.new(0, 0, 0 
,0),nil,nil,5)

object:TweenSize(UDim2.new(0, 400, 0, 
100))

local t = 10;

while wait() do

local hue = tick() % t / t

local color = Color3.fromHSV(hue,1,1)

script.Parent.BackgroundColor3 = color

end

You must put 4 spaces before each line, quotes in preformed text don’t always come out right.

Yeah, that worked thanks a lot!

1 Like

I think

while true do 
wait(0.1)

end

insert confusion here


wasn’t expected but alright

That’s not needed in their script, there’s already a while true do.

1 Like