Hello, I want to make rainbow bricks that cycle together. This is a gif of what I mean.
Make a table of all the parts
And a table of colors
Loop through the table of parts in order
And each time pick the next color in the table of colors - set the current part to that color
If you reach the end of the color table, wrap around to its start
If you name them in order and parent them to a fixed parent this script can make effect you showed :
local Parts = ["Parts Parent Here"]:GetChildren()
local offset = 0
while task.wait(1) do
offset += 1
offset %= #Parts
for index, part in Parts do
local hue = ((offset + index) / #Parts) % 1
part.Color = Color3.fromHSV(hue, 1, 1)
end
To make it faster you can reduce the wait value, adding more parts will make the effect look smoother.
This should do it.
RainbowColorBlocks.rbxl (41.6 KB)
local partList = {}
local numParts = #workspace.Parts:GetChildren()
for n = 1,numParts do
local part = workspace.Parts:FindFirstChild("Part_"..n)
table.insert(partList,part)
end
local colorList = {}
for n = 1,numParts do
local hue = (n / numParts) % 1
table.insert(colorList, Color3.fromHSV(hue, 1, 1))
end
local colorIndex = 1
while task.wait(.1) do
for n = 1,#partList do
local index = colorIndex+n
while index > #colorList do
index = index - #colorList
end
partList[n].Color = colorList[index]
end
colorIndex += 1
colorIndex %= #colorList
end
You can have the colorList be auto filled, as in the code, or you can specify your own colors.
Also note, the number of colors does NOT have to match the number of parts.
You could set color list to be
local colorList = {
Color3.new(1, 0, 0),
Color3.new(0, 0, 1)
}
and it would work fine with the 7 blocks.
It works great, thank you all for your replies.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.