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

[BrickColor] Why Does This Not Work? [Fixed]

Asked by 10 years ago

Why Does This Not Work? Trying to Change a Brick Color Of a Model I fixed my self so there is no need to choose an Answer

1doors = script.Parent:GetChildren()
2doors.BrickColor = BrickColor.new("Bright red")

3 answers

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

doors is a list of Bricks.

Lists don't have BrickColors, so changing the BrickColor of a list won't do anything.

You want to set the .BrickColor of the elements of the list, that is, of the bricks listed in the list.

You can get the ith element of a list like this: list[i]. There are #list things in a list, so we can use a loop to have i go from 1 to #list:

1for i = 1, #bricks do
2    local brick = bricks[i]
3    brick.BrickColor = BrickColor.new("Bright red")
4end

There are other iterators defined that make this a little shorter/semantic:

1for i, brick in pairs(bricks) do -- Figure out `brick` automatically
2    brick.BrickColor = BrickColor.new("Bright red")
3end

You want to be careful, though. If there are other things in the model that aren't Parts, this will error when you try to set their .BrickColor. We should add a check to be sure:

1for i, brick in pairs(bricks) do
2    if brick:IsA("BasePart") then
3        brick.BrickColor = BrickColor.new("Bright red")
4    end
5end
0
Hey I just wrote a long answer on this but it didn't post? Really? I spent 10 minutes on my answer. Might want to report this. Thetacah 712 — 10y
1
It's caused by the thread being renamed. I have a practice of pasting whatever I wrote int a textfile before pressing submit. BlueTaslem 18071 — 10y
Ad
Log in to vote
0
Answered by
foxy83 15
10 years ago

Is the syntax corrected like

1door.BrickColor = BrickColor.new("Cyan")

example??

Log in to vote
-6
Answered by 10 years ago

So i have an idea ,so lets asume the brick is in workspace you could do this

1local brick = game.Workspace.Brick
2brick.BrickColor = BrickColor.new("Bright Red")

Answer this question