What's the difference between those?

What’s the difference between:

1- workspace:GetChildren()

and

2- for i, v in pairs(workspace:GetChildren()) do

Don’t both loop through all the workspace children?

2 Likes

workspace:GetChildren() returns a table with all the elements parented under workspace.

However:

for i, v in pairs(workspace:GetChildren()) do
      -- etc.
end

This allows you to loop through each of the children within the table and do something with them.

For example:

for i, v in pairs(workspace:GetChildren()) do
      v:Destroy()
end

This would delete all children of workspace.

3 Likes

Aha I get it now!

Thank you so much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.