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

How do you get the children's of the children's in workspace?

Asked by 10 years ago

Hi, I'm trying to find out how to do this, I've tried many ways but they all throw an error, here is what I tried to use.

LobbyCount = game.Workspace:GetChildren()

for i, v in pairs(LobbyCount) do
                    Part = LobbyCount[i]:GetChildren()

                    if Part:FindFirstChild("PointLight") then
                        Part.PointLight.Enabled = false
                    end
                end

2 answers

Log in to vote
3
Answered by
jobro13 980 Moderation Voter
10 years ago

:GetChildren() returns a table. That's not what you want. You want to call :FindFirstChild() on the Part itself. Also, LobbyCount[i] == v.

So:

LobbyCount = game.Workspace:GetChildren()
for _, Part in pairs(LobbyCount) -- If you use logical variable names, this code gets easier to read and debug
    if Part:FindFirstChild("PointLight") then
        Part.PointLight.Enabled = true
    end
end
0
Thanks a lot. ^^ Slazerick 55 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Here ya go

local items = {}

function Scan(item)
    for i, v in pairs(item:GetChildren()) do
    print(v.Name)
    table.insert(items, v)
        if #v:GetChildren() > 0 then --Check if it has more children if so then Scan() again
            Scan(v)
        end
    end
end

Scan(game.Workspace)

--This will scan everything inside Workspace

for i, v in pairs(items) do --Get every object in the `items` table then set the pointlight to true
    if v.Name == "PointLight" then
    v.Enabled = true
    end
end
0
Giving a function is nice, and I must agree that this is a better approach. However, it's more valuable if you also post how this works, as the asker can then learn from this! :) jobro13 980 — 10y
0
ill edit it then DragonSkyye 517 — 10y

Answer this question