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

Smooth Color Changing Brick?

Asked by 6 years ago

Hello, I need help in creating a Smooth Color Changing Brick. I've seen some tutorials about brick color change but it does not make a smooth transition, it just instantly changes color. I am currently making a gaming chroma keyboard (Gaming keyboard that changes LED color from time to time, making a rainbow effect.)

Go see the PLACE so you see what I mean.

My current script for it is:

while true do
 script.parent.BrickColor = BrickColor.new("Steel blue")
 script.parent.Material = ("Neon")
 wait (3)

 script.parent.BrickColor = BrickColor.new("Bright violet")
 script.parent.Material = ("Neon")
 wait (3)

 script.parent.BrickColor = BrickColor.new("Magenta")
 script.parent.Material = ("Neon")
 wait (3)

 script.parent.BrickColor = BrickColor.new("Neon orange")
 script.parent.Material = ("Neon")
 wait (3)

 script.parent.BrickColor = BrickColor.new("Bright yellow")
 script.parent.Material = ("Neon")
 wait (3)

 script.parent.BrickColor = BrickColor.new("Lime green")
 script.parent.Material = ("Neon")
 wait (3)

 script.parent.BrickColor = BrickColor.new("Toothpaste")
 script.parent.Material = ("Neon")
 wait (3)

end

This is what I've just temporarily used as I am still asking for help.

5 answers

Log in to vote
0
Answered by
yyyyyy09 246 Moderation Voter
6 years ago

**This should work for your circumstances, comment if you have any questions about the code **

--[[ 
     Keep your colors in this table, they have the 
     .Color property which returns their Color3
     value for tweening
--]]
local colors = {BrickColor.new("Steel blue").Color, 
                BrickColor.new("Bright violet").Color,
                BrickColor.new("Magenta").Color,
                BrickColor.new("Neon orange").Color,
                BrickColor.new("Bright yellow").Color,
                BrickColor.new("Lime green").Color,
                BrickColor.new("Toothpaste").Color} 

local tweenService = game:GetService("TweenService")

script.parent.Material = ("Neon")

-- You don't need to set it to neon each time, only once

function ColorChange(colorToChangeTo)

    --[[ 
         Set Time, and Time2 as the same value, otherwise the tween will    
         play through the next time the ColorChange function runs
    --]]
    local tweenInformation = TweenInfo.new(1) -- Time1
    local ColorProperty = {}

    ColorProperty.Color = colorToChangeTo

    local tween = tweenService:Create(script.Parent,tweenInformation,ColorProperty)
    tween:Play()

    wait(1) -- Time2

end


while true do

    for i, v in ipairs(colors) do

        ColorChange(v)      

    end

end
0
Thank you so much, this worked for me! :) BanarMar -1 — 6y
0
sorry Zenith, I was literally doing it as you were doing, I only saw your answer after posting, but in this it's less of a hassle only using a single for loop, rather than 2. It's also easier to understand for beginners yyyyyy09 246 — 6y
0
Yeah, that's true, I agree. IMHO I think that Color3:lerp() is more simple (to me) than Tween because I'm used to Part lerping. I agree on the single loop, though. Although, why do you create a new function for ColorChange? It looks to me as it can just go in the for loop. Zenith_Lord 93 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
while true do
    script.Parent.BrickColor = BrickColor.Random()
    wait(0.05)
end

Is that what you're asking for?

0
If this is not desirable, just change each wait() to wait 0.05 seconds. DeceptiveCaster 3761 — 6y
0
Actually, you WOULD have to do this while setting shades of the desired colors, which creates a neat rainbow effect. DeceptiveCaster 3761 — 6y
0
Nope, i need a color changing brick that transitions SMOOTHLY, it's like as if it's naturally changing color. Not just from one color to another without a transition. BanarMar -1 — 6y
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You can use property tweening to achieve this. This is not gui tweening. You can find a tutorial here.

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

To create a smooth color-changing brick, I used Color3:lerp().

Here's the code:

local brick = script.Parent

local colors = {} -- Use a table to store the colors
table.insert(colors, BrickColor.new("Steel blue").Color) -- Use Color3 instead of BrickColor
table.insert(colors, BrickColor.new("Bright violet").Color)
table.insert(colors, BrickColor.new("Magenta").Color)
table.insert(colors, BrickColor.new("Neon orange").Color)
table.insert(colors, BrickColor.new("Bright yellow").Color)
table.insert(colors, BrickColor.new("Lime green").Color)
table.insert(colors, BrickColor.new("Toothpaste").Color) 

brick.Material = Enum.Material.Neon

while true do

    for i,v in pairs(colors) do
        brick.Color = v -- Use Color3 instead of BrickColor
        local nextColor = colors[i + 1]
        if(nextColor == nil) then -- End of table
            nextColor = colors[1]
        end

        wait(0.1)   
        for i = 0, 19 do -- 1 second transition, 20 iterations
            brick.Color = v:lerp(nextColor, i / 20) -- Slowly lerp/transition to next color         
            wait(0.05)
        end
    end
end
Log in to vote
0
Answered by 5 years ago

Im sorry to bring this back up, but if you'd like something very simple and goes through the whole spectrum, use this!

local Brick = script.Parent -- Put the part you are changing
local speed = 1 -- The speed that the colors change
while true do
    for i = 0,1,0.001*speed do
        Brick.Color = Color3.fromHSV(i,1,1)
        wait()
    end
end

Answer this question