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

How to make it stop at the 7th Child?

Asked by 6 years ago

This was the example for printing the names of all children of an object:

local children = Workspace:GetChildren() for i = 1, #children do print(i, children[i].Name) end

So i changed it to make my GUI become visible, without the locals and stuff:

for i = 1, #children do print(i, children[i].Name) children[i].Visible = true end

However, my 8th child is a Script, so it fails and doesn't continue the script since it can't become visible,

How do i make it stop before hitting the 8th Child?

0
Just check the classname to see if it is a script or not. hiimgoodpack 2009 — 6y

1 answer

Log in to vote
3
Answered by 6 years ago

To stop at a certain child, you would use an if statement and break:

for i=1,#children do
    if i==7 then
        break
    end
    print(i, children[i].Name)
    children[i].Visible=true
end

However, this is more of a hard-coded single-use method. It's better to check if the item is a GUI element with :IsA():

for i=1,#children do
    if children[i]:IsA("GuiObject") then --Checks if it's a GUI
        print(i, children[i].Name)
        children[i].Visible=true
    end
end

I hope this helped!

0
hi chip c; DanzLua 2879 — 6y
0
Oh, IsA can check if it is a guiobject easily? Nice hiimgoodpack 2009 — 6y
Ad

Answer this question