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

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

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

✓ Accepted answer
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

1 comment

0

Glad this helped :3

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