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

Error with GetChildren?

Asked by
Hybric 271 Moderation Voter
10 years ago

I am using GetChildren like this:

local cars = game.Workspace.Car:GetChildren()
for i = 1, #cars do
cars[i].BrickColor = BrickColor.Yellow()
end

But it justs finds one random part by using the table. What term finds All Children?

2 answers

Log in to vote
0
Answered by
jav2612 180
10 years ago

I don't see anything wrong in that script, it should work exactly how you want it to. However you should probably using in pairs for this application.

cars = game.Workspace.Car:GetChildren()
for i, v in pairs(cars) do
    if v:IsA("Part") then
        v.BrickColor = BrickColor.Yellow()
    end
end
0
Thank you, I will try it. Hybric 271 — 10y
0
Also it may because there is a child of "Car" that is not a part. This will cause the script to break. If there are any children in "Car" that arn't parts your going to need to check to make sure "v" is a part first before doing anything. jav2612 180 — 10y
0
I'll just edit to do that.... jav2612 180 — 10y
0
Well I LUA I fixed it all, but one problem, Okay so I have a Color3Value into the starterGui Gui called "Shop" and When I click a text button Hybric 271 — 10y
Ad
Log in to vote
0
Answered by 10 years ago
c=workspace:children()
for i=1,#c do
if c[i].className=="Part"then
c[i].BrickColor=BrickColor.new("Yellow") --Sorry if did this line wrong
elseif c[i].className=="Model"then
ci=c[i]:children()
for i2=1,#ci do
if ci[i2].className=="Part"then
ci[i2].BrickColor=BrickColor.new("Yellow") --Sorry if did this line wrong
end end end end

Answer this question