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

How to slowly shift BrickColor?

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.

2 comments

0

You can check out tweening. It will make the shifting even smoother.

0

sorry, I'm quite new to tweening. Do you know how to do it for the code I put in the question?

3 answers

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

1 comment

0

It's not just a brick, I need to do it with all parts in the model called Part.

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

5 comments

0

it are a few parts in a model I need to change.

0

and all those models need the same color

0

What do you mean?

0

just as I say, this code only changes 1 brick's color, it needs to change all bricks called "Part"

0

Oh.

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

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