Make loop include

I know I have a simple question…
This question was not solved by anyone successfully…
My question is…
Imagine you start this loop

For a, b in ipairs(folder:getchildren()) do
Wait 1
End

And while it is running you add another instance to the folder . The question is will it be included or not?

No it will not be included.

But how do you make it included???
Without restarting the loop?

7 Likes

You can turn the folder:getchildren() into a variable

local children = folder:getchildren()

You can use the event that runs when something gets added in the folder.

folder.ChildAdded:Connect(function(child)
    table.insert(children, child) -- and add it to the children
end)

Idk if that works, I never encountered questions like this before.

1 Like

What about checking it because I cannot check it right now

1 Like

wdym about checking the parts?

I’m talking about checking if it works because I’m 100% sure that it doesn’t work.

1 Like

Can you try if it works? I haven’t tried it yet so I don’t know.

1 Like

But what about just trying it I tried it many times before And other ways and since you still have the same tablet are not Updating it it will not work

1 Like

I need a method too update the table while the loop is running

1 Like

I believe I made a mistake above my post. Could you try again with this snippet?

I don’t see to snip at you are talking about

1 Like

Like I said I need a function that helps me to update

1 Like

If I don’t have a function to update it makes no sense

1 Like

Since the thing i’m trying to achieve is Making everything that cats added while the loop is running still be included

1 Like

Didn’t you see the code there?

In fact I didn’t see it but this is not solving the problem

1 Like

Like I said before I need the loop to update

1 Like

You didn’t see the event I wrote that fires everytime a new child has been added?

How do I have to place it? And also will it automatically update the loop without having to run it again?

1 Like

To answer your question? Yes, I did see it but I do not understand how I have to implement that.

1 Like

I want to loop to run and include everything. Because I needed for an entity my door Game. If I were to restart a loop, the entity would not go smoothly through the rooms

1 Like