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

Changing brickcolor problem?

Asked by
Paldi 109
10 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 — 10y

3 answers

Log in to vote
1
Answered by
Paldi 109
10 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
Ad
Log in to vote
0
Answered by 10 years ago

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
Log in to vote
0
Answered by
Kratos232 105
10 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

For more info on GetChildren(), go here.

Well, hope I helped. :)

  • Kratos232

Answer this question