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

How would I check the children of the children in workspace?

for _, brick in pairs (game.Workspace:GetChildren()) do
	if brick.Name == "Wall" then
	print("found the wall")
	end
end

This script checks for the children of workspace for a part named "Wall". However "Wall" is in a model which is a child of workspace...how would I get the wall part because the lines above only seem to search through Workspace and not the models inside of it.

3 comments

0

:IsDescendantOf

0

Can't you just do game.workspace.WhatEverTheModelNameIs:GetChildren()

0

No because there are multiple models.

1 answer

✓ Accepted answer

I'm assuming you want to scan the entire file structure of workspace. You need to create a function that scans a given table for the object you want. That function will call itself on every object it finds to scan its children and so on. This is the general idea:

function scan(table)
	for _, v in pairs (table) do
		print(v)
		scan(v:GetChildren())
	end
end

scan(game.Workspace:GetChildren())

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