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.
**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
while true do script.Parent.BrickColor = BrickColor.Random() wait(0.05) end
Is that what you're asking for?
You can use property tweening to achieve this. This is not gui tweening. You can find a tutorial here.
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
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