Make loop include

The problem is that I don’t know how the original creator stood it

1 Like

You basically want a FOR-loop to act as a while loop, because you want the loop’s length to continuously update as rooms are added to the folder mid-loop. This isn’t advised because FOR-loops are designed for a fixed iteration amount.

Assuming you don’t care about efficiency, this while loop answers your question more or less.

local folder = -- As you wish

local i = 1
while true do
    local children = folder:GetChildren()
    if i <= #children then
        local child = children[i]
        
        -- A room was added during the loop, do something...
        
        wait(1)
        i = i + 1
    else
        -- Otherwise, you can break the loop if there's no new rooms.
        -- And all other rooms have been iterated over.
        wait(1) 
    end
end

the script is pretty simple, we first iterate through the un-updated array. after, we check if anything is added via the:

#folder:GetChildren() > #folder_children

if the check is true, we start at an index above the last index to keep continuing with another for loop at the adjusted index when there are more children added.

So if I add something, why the loop is running?
It will not restart it and just Continue until all instances we’re going through.? Without Without restarting at room one question

1 Like

im not sure im understanding what you’re saying

So imagine the following okay just try to understand it

1 Like

The Entity starts rushing through the rooms.
Now another room generates in the folder.
What will the entity do after Reached the last room that was Created before the loop was started.?
Or will it restart from room one and go to everything again.
Or will it keep the numerizing for example, if the added room is called 11, will it then Go to room eleven?

1 Like

I hope this helps you to better understand what I am saying

1 Like

if the added room is 11, it will go to room 11, hence the “new_index” variable. you can try the script if you want.

No I cannot since it is.4 The morning and I do not have access to my computer yet.

1 Like

Then you could try later with all of the snippets provided above. You wouldn’t truly know if something works without trying it.

Yes, I do because I can read scripts. But yet normally what you say is true

1 Like

I need the entity to go through all rooms that get added

1 Like

My main problem is that I don’t know How to get that scripted inside of my script

1 Like

Replace your current script with the snippet above.

How am I supposed to do that You don’t even know how complicated my script looks

1 Like

And if that is not enough already I also need to make it able to rebound

1 Like

That’s because I don’t know how your script looks at all.

Well would you like to see it? If yes that I could Just show you how it looks like I can just pay the entire code here

1 Like

You can decide if you want me to see your code. It is easier if we see your code and observe.