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

Is there a way to change the color of multiple blocks in just one string?

Asked by 10 years ago

The title pretty much says it all but, say if I didn't want to type out each one.

Something like this:

a = game.Workspace.Part1,Part2,Part3

a.BrickColor = BrickColor.new(1004) 

I know that script would not work but is there any way like it?

I don't really care to type it out like this:

a = game.Workspace.Part1
b = game.Workspace.Part2
c = game.Workspace.Part3

a.BrickColor = BrickColor.new(1004)
b.BrickColor = BrickColor.new(1004)
c.BrickColor = BrickColor.new(1004)


I've got 88 parts that I need to change the color 24 times.

Thanks, Bb1

0
A general tip: Use brick color names as the parameter to BrickColor.new instead of the number. It makes it a lot easier to read and figure out! BlueTaslem 18071 — 10y

2 answers

Log in to vote
0
Answered by
Ekkoh 635 Moderation Voter
10 years ago

You could make a function to change the color of all the parts.

local parts = Workspace.Model -- Location of parts

function setColor(color)
    for _, p in pairs(parts:GetChildren()) do
        p.BrickColor = BrickColor.new(color)
    end
end

-- example
while true do
    setColor("Bright red")
    wait(20)
    setColor("Bright blue")
    wait(40)
end
0
Thank you very much! I found yours the most helpful and it works. bestbudd1 45 — 10y
Ad
Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

Well, yes. If you wouldn't mind grouping them all together, then it'll be possible to do it all in less lines. You'd need to use either the generic for loop or the numeric for loop. I'll use the generic.

Model = game.Workspace["Model"]:GetChildren() -- You can obviously change the name to your liking.

for i,v in pairs(Model) do
    v.BrickColor = BrickColor.new(1004)
    wait(1)
    v.BrickColor = BrickColor.new(1003) -- Really black
end
0
Thank You, I'm going to test this right now. bestbudd1 45 — 10y
0
No problem. Shawnyg 4330 — 10y

Answer this question