Still have questions? Join our Discord server and get real time help.
2

# Changing brickcolor problem?

Paldi 109
6 years ago

I have a script to change the color of some parts in a group but it change all of them, what i did wrong?

there is no errors but it just gets all the parts and i want it to only get the parts called "Color1"

    local h = player.Character:findFirstChild("Chest"):getChildren("Color1")
for i = 1, # h do
h[i].BrickColor = BrickColor.new(clothesC.Value)
end


thanks for helping!

0
If I understand correctly, you're trying to change the colour of their left arm. Would it be possible to edit a thing in the player called BodyColors, instead, sorry, just an idea. Mystdar 352 — 6y

1
Paldi 109
6 years ago

i needed to do it like this, if it can help anyone..

    local j = player.Character:findFirstChild("LeftArm"):getChildren()
for i = 1, # j do
if j[i].Name == "Color1" then
j[i].BrickColor = BrickColor.new(clothesC.Value)
end
end

0

Using the example from the 1st post you would need some code like this

local h = player.Character:FindFirstChild("Chest"):GetChildren()
for i, v in pairs(h) do
if v.Name == "Color1" then
v.BrickColor = BrickColor.new(clothesC.Value)
end
end

0
Kratos232 100
6 years ago

The only problem I see in your script, is your use of the "GetChildren()" method.

GetChildren() "Returns a read-only table of the object's children", as in, it returns ALL the children of the Instance you use it on (In a Table).

In your script, you try to use it to get all the children called "Color1", but since GetChildren() really doesn't care about the Parameters you use, it returns ALL the children.

An easy way to fix it would be to put an "if statement" in the for loop, to check the name, like so...

local h = player.Character:findFirstChild("Chest"):getChildren() --// Removed the "Color1" from it.

for i = 1, # h do
if h[i].Name == "Color1" then
h[i].BrickColor = BrickColor.new(clothesC.Value)
end
end