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

[SOLVED] Needing help with GetChildren?

I'v been trying to work out how to make a script which gets the children from the model then changes their color to a certain color i.e. Bright blue.

This is horrible:

local children = Workspace.Backpack:GetChildren()
for i = 1, #children do
    children.BrickColor = BrickColor.new("White")
end

2 answers

✓ Accepted answer

GetChildren() gets an objects children and should be used in table format.

for a,b in pairs(game.Workspace.BackPack:GetChildren()) do
	if b:IsA("BasePart") then
		b.BrickColor = BrickColor.new("White")
	end
end
local children = Workspace.Backpack:GetChildren()
for i = 1, #children do
    children[i].BrickColor = BrickColor.new("Pink")
end

2 comments

1

^ I'd use in pairs for this instead of a for i = loop... Just saying :#

1

^ Besides you didn't even check to make sure that all the children are BaseParts. Your script would break if there was a script/tool/ect.

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