Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a fancy object in ROBLOX Studio to transmit from 1 color to another smoothly?

###Hey guys,

I was wondering if there is some fancy object or some cool method that I can script to make an object transmit from 1 color to another by going through smooth phases. Like, let's say from white to black, it would go: White, Light grey, Grey, Light Black, Black. Smoothly transitioning from one color to another like that by going through the phases.

##Any help is appreciated.

~~ KingLoneCat

1 comment

0

Color3 or Brick Color?

3 answers

##Lerp

You can use the lerp function on Color3 datatypes. "Lerp" is short for "Linear Interpolation", and takes in 2 arguments:

  • Color3 end goal: What you're trying to get to

  • Number alpha: Number between 0 and 1, acting as a percentage between start and end


##Usage

Since you're looking for a smooth transition, you should use a numerical for loop. Syntax looks like this:

for [var] = [start],[finish],[(optional) increment] do

[code]

end

Use your color goal as the first argument in the Lerp function, and then your [var] divided by your [finish] to indicate a gradual climb.


##Code

local part = workspace.Part --This is your part
local color = Color3.new(0,0,0) --This is the desired color; black
local smooth = 20 --This is how smooth the transition will be

for i = 1,smooth do
	local c = part.BrickColor.Color:lerp(color,i/smooth); --Aquire the color
	print(BrickColor.new(c.r,c.g,c.b));
	part.BrickColor = BrickColor.new(c.r,c.g,c.b) --Convert to BrickColor
	wait(.05)
end

Note: BrickColors and Color3s do not translate perfectly. You may notice some odd colors pop up but for the most part, the transition is normal.

8 comments

0

Why did you do i/smooth for the second argument in the :lerp() is it ok if I replace that with a color3?

0

I already explained that at the end of the Usage section - it will cause a gradual climb. if i is 1 then it will be 1/20, which is 5% progress in between your starting color and your wanted color. If i is 2, it will be 10%, and if i is smooth, it will be 100%. Understand?

0

No it is not ok to replace it with a Color3. Look at my explanation on the second argument for the Lerp function .-.

0

So, what if I want the 2 colors to be different then just black and white? Let's say I want it to be blue and pink.

0

Then the color of the part has to already be blue, and you have to set the 'color' variable to a Color3 datatype that corresponds to pink

0

you are such a ####### help!

0

you are such an epic helper*!

0

this deserves upvotes dude

You could try this, a Color3 lerp function. For example,

local start = Color3.new(1,1,1)-- White
local End = Color3.new(0,0,0)--Black

for i = 0,1,0.03 do
    wait()
    local color = start:lerp(End,i)
end

2 comments

0

"Red"

0

Typo, fixed it now.

  1. Make the brick white
  2. Place black decals around the brick
  3. Comment to me if you don't know how to make a smoothly decal transparency & I edit my answear

2 comments

0

That's not what I meant.

0

But it looks like that in the colors...

This discussion is preserved as it was. New answers, comments, and votes are closed.