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

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

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

: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

1 comment

0

Thanks a lot. ^^

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

2 comments

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! :)

0

ill edit it then

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