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

Why doesn't my loop change all parts' colors?

Asked by
Jexpler 63
6 years ago

I have a simple script that is supposed to turn a player's skin tone to light blue.

hit.Parent["Body Colors"]:Destroy()
for i,v in pairs(hit.Parent:GetChildren()) do
    if v.ClassName == "Part" then
        v.BrickColor = BrickColor.new("Light blue")
    end
end

"hit" represents a limb, so hit.Parent is the character's model. For some reason it only does it to one part.

1
if you add a wait() before the for loop it will work aazkao 787 — 6y

2 answers

Log in to vote
1
Answered by
IcyEvil 260 Moderation Voter
6 years ago

I am a bit rusty, so this may or may not work, but in my own experience I had to go do each individual body part when I wanted to change skin color/ material color/ transparency.

hit.Parent['Body Colors']:Destroy() -- Destroys Body Colors
    for _,v in pairs(hit.Parent:GetChildren()) do -- Turns v into all Children of Parent
        if v.ClassName == "Part" then -- Checks to see if the Childrens class is "Part"
            v.BrickColor = BrickColor.new("Light blue") -- Tries to turn all children with classname "part" to color Light blue
        end
    end

I am terrible at explaining what you did wrong, so let me see if I can come up with a solution. Remember I am rusty to high h*ll so forgive me.

hit.Parent['Body Colors':Destroy()
    for _,v in pairs(hit.Parent:GetChildren()) do
        if v.ClassName == "Part" then
            v["Left Leg"].BrickColor = BrickColor.new("Light blue")
            v["Right Leg"].BrickColor = BrickColor.new("Light blue")
            v["Left Arm"].BrickColor = BrickColor.new("Light blue")
            v["Right Arm"].BrickColor = BrickColor.new("Light blue")
            v["Torso"].BrickColor = BrickColor.new("Light blue")
            v["Head"].BrickColor = BrickColor.new("Light blue")
        end
    end
end 

This may or may not work, like I said I am pretty rusty.

0
a "for loop" literates through a table, it doesnt just makes the variable everything in the table User#23365 30 — 6y
0
also use :IsA() instead of checking the classname and use "BasePart" instead of "Part" User#23365 30 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
script.Parent.Touched:Connect(function(hit)
    hit.Parent:FindFirstChild("Body Colors"):Remove()
    for _,ctype in pairs(hit.Parent:GetChildren()) do -- ctype stands for class type
        if ctype:IsA("Part") then
        ctype.BrickColor = BrickColor.new("Light blue")
    end
    end
end)

Answer this question