How to getchildren() through multiple parents

Capture
I’m new to scripting and I was playing around with the getchildren() function. I ran into an issue when I was trying to call a child through multiple parents and printing it, but it printed nothing. He is the script I came up with so far:

local children = Players.unknown.playergui:GetChildren()
for i = 1, #children do
local child = children[i]
print(child.Name)
end

The output i would like is
BubbleChat
Chat
Freecam

This is just an example and by no means am I going to use it, I just want to learn how to so I can make it work with my other script

Please and thanks :smiley: - Noob scripter

Check out the article pairs and iPairs (roblox.com)
For your example, you could use a pairs loop to print everything in PlayerGui like this:

for _, child in pairs(Players.unknown.PlayerGui:GetChildren()) do
    print(child.Name)
end

I would make a better reference than Players.unknown though as this script would error if the player wasn’t explicitly named “unknown”

2 Likes