Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to smoothly change Color of a Brick?

Asked by 5 years ago

I just wanted to ask how to smoothly change the Color of a Brick to another Random Color

actually this is the only thing I have

local br = script.Parent.BrickColor
local nbr = BrickColor.Random()

And I want br to smoothly change to nbr How can I do this?

1 answer

Log in to vote
4
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

You are able to use TweenService to smoothly transition between a whole range of properties (listed here). Color3s are one of these data types.

To create a tween, you first need to make a dictionary with the key of the property and the value of the goal colour:

local Goal = {
    Color = BrickColor.Random().Color --we want to get the Color3 part of the BrickColor
}

Then, we want to create the TweenInfo, which contains details about how the tween will work:

local Info = TweenInfo.new(3,Enum.EasingStyle.Linear) --tween will take 3 seconds and have a linear transition

After that, you can create the tween with that information and play it:

local Tween = game:GetService("TweenService"):Create(script.Parent, Info, Goal)
Tween:Play()

The part should then transition from the colour it is currently at to the new random goal colour. If you wanted to repeat this, you can set the RepeatCount parameter of TweenInfo.new() to math.huge (so it repeats indefinitely).

0
Thanks :) RicheeNektar 78 — 5y
0
If you set the RepeatCount property to a value less than 0, or just leave it out altogether, it will also repeat infinitely - this avoids a slightly nasty math.huge. fredfishy 833 — 5y
0
Gotcha, great idea, except wont leaving it out be equivalent to setting it to nil, which will default to only playing once? mattscy 3725 — 5y
Ad

Answer this question