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 4 years ago

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

items = {}

for index, descendant in pairs(script.Parent.Model:GetDescendants()) do
    if descendant.Name == "Part" then
        table.insert(items, descendant)
    end
end

while true do
    for i, v in items do
        -- What do I do now?
    end

    wait(math.random(0.95, 1.05)) -- Stay as solid color for a very short while
end

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 — 4y
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 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

Here is the gist

local tween = function(Object, Changes)
    local Info = TweenInfo.new(
        .5, --Time to do the tween
        Enum.EasingStyle.Back, -- Style
        Enum.EasingDirection.Out, -- Direction
        0, -- number of repeats
        false, -- reverts back to normal
        0 -- Delay 
    )
    local TweenService = game:GetService("TweenService")
    local Action = TweenService:Create(Object, Info, Changes)
    return Action
end


while true do
    local Action = tween(script.Parent, {Color = Color3.fromRGB(math.random(0,255), math.random(0,255), math.random(0,255))})
    Action:Play()
    Action.Completed:Wait()
end

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 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
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} -- the colors table, you change change them.

local tweenService = game:GetService("TweenService")

script.parent.Material = ("Neon") --The Mateiral

function ColorChange(colorToChangeTo) --color change function

    local time = 3 --Set this to the time
    local tweenInformation = TweenInfo.new(time) 
    local ColorProperty = {}

    ColorProperty.Color = colorToChangeTo

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

    wait(time)

end


while true do

    for i, v in ipairs(colors) do --colors

        ColorChange(v)      

    end

end
--https://gyazo.com/47c0a30384534f038b6b735cf07efc97
0
it are a few parts in a model I need to change. BeAHacker666 75 — 4y
0
and all those models need the same color BeAHacker666 75 — 4y
0
What do you mean? GamingWithFlight 80 — 4y
0
just as I say, this code only changes 1 brick's color, it needs to change all bricks called "Part" BeAHacker666 75 — 4y
0
Oh. GamingWithFlight 80 — 4y
Log in to vote
0
Answered by 4 years ago

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

local items = {}

for index, descendant in pairs(script.Parent.Model:GetDescendants()) do
    if descendant.Name == "Part" then
        table.insert(items, descendant)
    end
end

function positify(val)
    if val < 0 then
        return -val
    else
        return val
    end
end

while true do
    local newR = math.random(255) / 255
    local newG = math.random(255) / 255
    local newB = math.random(255) / 255

    local running = true

    while running do
        for i, v in pairs(items) do
            if v.Color.r > newR then
                v.Color = Color3.new(v.Color.r - 1 / 255, v.Color.g, v.Color.b)
            elseif v.Color.r < newR then
                v.Color = Color3.new(v.Color.r + 1 / 255, v.Color.g, v.Color.b)
            end

            if v.Color.g > newG then
                v.Color = Color3.new(v.Color.r, v.Color.g - 1 / 255, v.Color.b)
            elseif v.Color.g < newG then
                v.Color = Color3.new(v.Color.r, v.Color.g + 1 / 255, v.Color.b)
            end

            if v.Color.b > newB then
                v.Color = Color3.new(v.Color.r, v.Color.g, v.Color.b - 1 / 255)
            elseif v.Color.b < newB then
                v.Color = Color3.new(v.Color.r, v.Color.g, v.Color.b + 1 / 255)
            end

            if positify(newR - v.Color.r) <= 1 / 255 then
                if positify(newG - v.Color.g) <= 1 / 255 then
                    if positify(newB - v.Color.b) <= 1 / 255 then
                        running = false
                    end
                end
            end
        end

        wait()
    end

    wait(math.random(0.95, 1.05)) -- Stay as solid color for a very short while
end

Answer this question