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")
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 i
th 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
Is the syntax corrected like
door.BrickColor = BrickColor.new("Cyan")
example??
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")