Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Error with GetChildren?

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

✓ Accepted answer

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

4 comments

0

Thank you, I will try it.

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.

0

I'll just edit to do that....

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.