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

doors = script.Parent:GetChildren()
doors.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:

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

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

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

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:

for i, brick in pairs(bricks) do
    if brick:IsA("BasePart") then
        brick.BrickColor = BrickColor.new("Bright red")
    end
end
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

door.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

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

Answer this question