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 7 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 — 7y

1 answer

Log in to vote
3
Answered by 7 years ago

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

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

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

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

I hope this helped!

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

Answer this question