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

How come it only worked on one part only and how do I shorten this script w/o copy and paste?

Asked by 8 years ago

I made a script where it is supposed to change colors to the colors I put in. Well, it only worked on the first part, as in part1 not the rest of them. I also want to know if there is a way to shorten this script to make it easier. I know it might have to do with using Table, but I am not familiar with it. This is the script:

local part1 = game.Workspace.ColorChangers.Part1

while true do
part1.BrickColor = BrickColor.new("Bright Orange")
wait(0.1)
part1.BrickColor = BrickColor.new("New Yeller")
wait(0.1)
part1.BrickColor = BrickColor.new("Dark green")
wait(0.1)
part1.BrickColor = BrickColor.new("Really blue")
wait(0.1)
part1.BrickColor = BrickColor.new("Royal purple")
wait(0.1)
part1.BrickColor = BrickColor.new("Bright red")
wait(0.1)
end

local part2 = game.Workspace.ColorChangers.Part2

while true do
part2.BrickColor = BrickColor.new("New Yeller")
wait(0.1)
part2.BrickColor = BrickColor.new("Dark green")
wait(0.1)
part2.BrickColor = BrickColor.new("Really blue")
wait(0.1)
part2.BrickColor = BrickColor.new("Royal purple")
wait(0.1)
part2.BrickColor = BrickColor.new("Bright red")
wait(0.1)
part2.BrickColor = BrickColor.new("Bright Orange")
wait(0.1)
end

local part3 = game.Workspace.ColorChangers.Part3

while true do
part3.BrickColor = BrickColor.new("Dark green")
wait(0.1)
part3.BrickColor = BrickColor.new("Really blue")
wait(0.1)
part3.BrickColor = BrickColor.new("Royal purple")
wait(0.1)
part3.BrickColor = BrickColor.new("Bright red")
wait(0.1)
part3.BrickColor = BrickColor.new("Bright Orange")
wait(0.1)
part3.BrickColor = BrickColor.new("New Yeller")
wait(0.1)
end

1 answer

Log in to vote
5
Answered by
Ryzox 220 Moderation Voter
8 years ago
local Colors = {"Dark green","Really blue","Royal purple","Bright red","Bright Orange","New Yeller"}

local part1 = workspace.ColorChangers.Part1
local part2 = workspace.ColorChangers.Part2
local part3 = workspace.ColorChangers.Part3

while wait() do -- will loop this
    for index,color in pairs(Colors) do -- loops through every color in the Colors table and makes bricks that color
        part1.BrickColor = BrickColor.new(color)
        part2.BrickColor = BrickColor.new(color)
        part3.BrickColor = BrickColor.new(color)
        wait(0.1) -- waits 0.1
    end
end

You could also make the bricks have different colors at same time by doing this for the loop:

while wait() do -- will loop this
    for index,color in pairs(Colors) do -- loops through every color in the Colors table and makes bricks that color
        part1.BrickColor = BrickColor.new(color)
        part2.BrickColor = BrickColor.new(Colors[index+1] or Colors[1]) -- Makes it the next color in the table or the first color in the table if there is not another value next in the table
        part3.BrickColor = BrickColor.new(Colors[index-1] or Colors[6]) -- same as last but only doing colors before.
        wait(0.1) -- waits 0.1
    end
end
0
Glad this helped :3 Ryzox 220 — 8y
Ad

Answer this question