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

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

Asked by 8 years ago
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.

0
:IsDescendantOf theCJarmy7 1293 — 8y
0
Can't you just do game.workspace.WhatEverTheModelNameIs:GetChildren() Kryddan 261 — 8y
0
No because there are multiple models. SHDrivingMeNuts 299 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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())
Ad

Answer this question