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!
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
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
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
For more info on GetChildren(), go here.
Well, hope I helped. :)