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

How to make it stop at the 7th Child?

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?

1 comment

0

Just check the classname to see if it is a script or not.

1 answer

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!

2 comments

0

hi chip c;

0

Oh, IsA can check if it is a guiobject easily? Nice

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