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

How to slowly shift BrickColor?

Asked by 5 years ago

I have an model where all descendants called Part need to slowly shift color, here's the code I already have:

01items = {}
02 
03for index, descendant in pairs(script.Parent.Model:GetDescendants()) do
04    if descendant.Name == "Part" then
05        table.insert(items, descendant)
06    end
07end
08 
09while true do
10    for i, v in items do
11        -- What do I do now?
12    end
13 
14    wait(math.random(0.95, 1.05)) -- Stay as solid color for a very short while
15end

I'd rather have my game run nice and smooth, but if no one knows how to make this code also smooth I'll just use the best other code I can find.

0
You can check out tweening. It will make the shifting even smoother. DeceptiveCaster 3761 — 5y
0
sorry, I'm quite new to tweening. Do you know how to do it for the code I put in the question? BeAHacker666 75 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago

Here is the gist

01local tween = function(Object, Changes)
02    local Info = TweenInfo.new(
03        .5, --Time to do the tween
04        Enum.EasingStyle.Back, -- Style
05        Enum.EasingDirection.Out, -- Direction
06        0, -- number of repeats
07        false, -- reverts back to normal
08        0 -- Delay
09    )
10    local TweenService = game:GetService("TweenService")
11    local Action = TweenService:Create(Object, Info, Changes)
12    return Action
13end
14 
15 
16while true do
17    local Action = tween(script.Parent, {Color = Color3.fromRGB(math.random(0,255), math.random(0,255), math.random(0,255))})
18    Action:Play()
19    Action.Completed:Wait()
20end

Put this in a brick

0
It's not just a brick, I need to do it with all parts in the model called Part. BeAHacker666 75 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
01local colors = {BrickColor.new("Steel blue").Color,
02                BrickColor.new("Bright violet").Color,
03                BrickColor.new("Magenta").Color,
04                BrickColor.new("Neon orange").Color,
05                BrickColor.new("Bright yellow").Color,
06                BrickColor.new("Lime green").Color,
07                BrickColor.new("Toothpaste").Color} -- the colors table, you change change them.
08 
09local tweenService = game:GetService("TweenService")
10 
11script.parent.Material = ("Neon") --The Mateiral
12 
13function ColorChange(colorToChangeTo) --color change function
14 
15    local time = 3 --Set this to the time
View all 38 lines...
0
it are a few parts in a model I need to change. BeAHacker666 75 — 5y
0
and all those models need the same color BeAHacker666 75 — 5y
0
What do you mean? GamingWithFlight 80 — 5y
0
just as I say, this code only changes 1 brick's color, it needs to change all bricks called "Part" BeAHacker666 75 — 5y
0
Oh. GamingWithFlight 80 — 5y
Log in to vote
0
Answered by 5 years ago

Nvm, I found a solution myself, it might now be the smoothest but I'm fine with it.

01local items = {}
02 
03for index, descendant in pairs(script.Parent.Model:GetDescendants()) do
04    if descendant.Name == "Part" then
05        table.insert(items, descendant)
06    end
07end
08 
09function positify(val)
10    if val < 0 then
11        return -val
12    else
13        return val
14    end
15end
View all 57 lines...

Answer this question