Make loop include

i hope this helps you sir

local function s_t(t)
     local s = 0
     for _, _ in pairs(t) do
          s = s+ 1
     end
end

local function do_thing(a)

end

local ct = f:GetChildren()
local i = 0
local nc = s_t(childrenTable)

local ca_c = nil

local d = 1

while i < nc or (0 == 1) do
     if ca_c ~= nil then 
          ca_c:Disconnect()
          ca_c = nil
     end

     ca_c = f.ChildAdded:Connect(function(c) 
           nc = nc + 1
           ct[nc] = c
     end)

    local cc = ct[i]
    do_thing(cc) -- do thing to instance

     i = i + 1
     wait(d)
end

if you need anything explained im busy so ask someone else

i believe that this script can help you

local folder: Folder
local children = folder:GetChildren()

local INDEX = 1
while true do
  if INDEX > #children then break end
  local instance = children[INDEX]
  --code

  INDEX += 1
end

folder.ChildAdded:Connect(function(i)
  table.insert(children, i)
end)

folder.ChildRemoved:Connect(function(i)
  local tf = table.find(children, i)
  if tf then
    table.remove(children, tf)
  end
end)

what it does is connect to the event that fires whenever a child is added to the folder, and adds it to the list containing all the children of the folder. since it is not iterating directly through the list passed through the pairs() function, the loop will dynamically contain all of the children within the folder during the loop. i have also handled children being removed too.

No offense but the naming gets me confused.

1 Like

You could send the specific script you’re having trouble or trying to implement on. Sending a whole project is risky.

my initial code looks like this.

local Rush_DB = true
function Rush()
	if Rush_DB then Rush_DB = false

		if script.ENTITY_FOLDER.ACTIVE_RUSH.Value ~= nil then
			script.ENTITY_FOLDER.ACTIVE_RUSH.Value:Destroy()
		else
		end


		script.EVENTS.LIGHTS_CONTROLLER:Fire("FLICKER")
		script.EVENTS.HIDING_HIGHLIGHT:Fire()
		wait(4)

		local Cloned_Rush = script.ENTITY_FOLDER.RUSH.Value:Clone()

		script.ENTITY_FOLDER.ACTIVE_RUSH.Value = Cloned_Rush

		Cloned_Rush.Parent = game.Workspace

		--game.Debris:AddItem(Cloned_Rush,20)


		Cloned_Rush.RUSH.CHASE:Play()
		Cloned_Rush.RUSH.CHASE_INNER:Play()

		local SPAWN_ROOM_NUMBER = script.ROOM_AMOUNT.Value -6

		local SPAWNROOM = script.ACTIVE_ROOMS_FOLDER.Value:FindFirstChild(SPAWN_ROOM_NUMBER)

		Cloned_Rush.CFrame = script.SPAWN_ROOM.Value:FindFirstChild("END").CFrame

		wait(4)


		local alreadyMovedTo = {}
		for a,b in pairs(script.ACTIVE_ROOMS_FOLDER.Value:GetChildren()) do
			table.insert(alreadyMovedTo,b)
			if b:FindFirstChild("CHASE_NODES") then
				for c,d in ipairs(b.CHASE_NODES:GetChildren()) do
					if Cloned_Rush.RUSH.DAMAGE.RUNNING.Value == true then
						local anglePart = d
						if anglePart then
							game.TweenService:Create(Cloned_Rush,TweenInfo.new(script.ENEMY_SPEED.Value,Enum.EasingStyle.Linear),{CFrame = anglePart.CFrame * CFrame.new(0,0,0)}):Play()
							task.wait(script.ENEMY_SPEED.Value)
						end
					else
					end
					task.wait()
					if #script.ACTIVE_ROOMS_FOLDER.Value:GetChildren() > #script.ACTIVE_ROOMS_FOLDER.Value:GetChildren() and a >= #script.ACTIVE_ROOMS_FOLDER.Value:GetChildren() then
						task.wait(script.ENEMY_SPEED.Value)
						local done = 0
						for c,d in pairs(script.ACTIVE_ROOMS_FOLDER.Value:GetChildren()) do
							if not table.find(alreadyMovedTo,d) then
								if b:FindFirstChild("CHASE_NODES") then
									for e,f in ipairs(d.CHASE_NODES:GetChildren()) do
										if Cloned_Rush.RUSH.DAMAGE.RUNNING.Value == true then
											local anglePart = f
											if anglePart then
												game.TweenService:Create(Cloned_Rush,TweenInfo.new(script.ENEMY_SPEED.Value,Enum.EasingStyle.Linear),{CFrame = anglePart.CFrame * CFrame.new(0,0,0)}):Play()
												task.wait(script.ENEMY_SPEED.Value)
											end
										end
									end
								end
							end
						end
					end
				end
			end
		end

		if script.ENTITY_FOLDER.ACTIVE_RUSH.Value ~= nil then
			if script.ENTITY_FOLDER.ACTIVE_RUSH.Value.RUSH.RUNNING.Value == true then
				script.ENTITY_FOLDER.ACTIVE_RUSH.Value:Destroy()
			end
		end

		Rush_DB = true
	end
end
1 Like

there do you have the script you requested

1 Like

i would like to get explained how this code works

1 Like

i tried it and it didnt work. sorry ):

1 Like

please explain how this works. i dont understand it

1 Like

thanks you for trying to help me. this is what i made out of your code… is it correct?

		local MyTable = script.ACTIVE_ROOMS_FOLDER:GetChildren()
		local TrackTime = 0

		script.ACTIVE_ROOMS_FOLDER.Value.ChildAdded:Connect(function(Obj)
			table.insert(MyTable, Obj)
		end)

		TrackTime = table.maxn(MyTable)
		for a, b in ipairs(MyTable) do
			if table.maxn(MyTable) ~= TrackTime then
				return b
			else
				
				if b:FindFirstChild("CHASE_NODES") then
					for c,d in ipairs(b.CHASE_NODES:GetChildren()) do
						if Cloned_Rush.RUSH.DAMAGE.RUNNING.Value == true then
							local anglePart = d
							if anglePart then
								game.TweenService:Create(Cloned_Rush,TweenInfo.new(script.ENEMY_SPEED.Value,Enum.EasingStyle.Linear),{CFrame = anglePart.CFrame * CFrame.new(0,0,0)}):Play()
								task.wait(script.ENEMY_SPEED.Value)
							end
						else
						end
					end
				end
				wait(1)
			end
		end
1 Like

this script is unable to make rush move even one single room. it directly makes him disappear

1 Like

where to put the tween stuff??? i dont know where to put it?

1 Like

i dont seee a for a,b do loop, is there?

1 Like

how does this work? i need to include this code into it to make it go trough the rooms!

		for a, b in ipairs(MyTable) do
			if b:FindFirstChild("CHASE_NODES") then
				for c,d in ipairs(b.CHASE_NODES:GetChildren()) do
					if Cloned_Rush.RUSH.DAMAGE.RUNNING.Value == true then
						local anglePart = d
						if anglePart then
							game.TweenService:Create(Cloned_Rush,TweenInfo.new(script.ENEMY_SPEED.Value,Enum.EasingStyle.Linear),{CFrame = anglePart.CFrame * CFrame.new(0,0,0)}):Play()
							task.wait(script.ENEMY_SPEED.Value)
						end
					else
					end
				end
			end
1 Like

how does this work? i need to include this code into it to make it go trough the rooms!

		for a, b in ipairs(MyTable) do
			if b:FindFirstChild("CHASE_NODES") then
				for c,d in ipairs(b.CHASE_NODES:GetChildren()) do
					if Cloned_Rush.RUSH.DAMAGE.RUNNING.Value == true then
						local anglePart = d
						if anglePart then
							game.TweenService:Create(Cloned_Rush,TweenInfo.new(script.ENEMY_SPEED.Value,Enum.EasingStyle.Linear),{CFrame = anglePart.CFrame * CFrame.new(0,0,0)}):Play()
							task.wait(script.ENEMY_SPEED.Value)
						end
					else
					end
				end
			end..
1 Like

how does this work? i need to include this code into it to make it go trough the rooms! please help!

		for a, b in ipairs(MyTable) do
			if b:FindFirstChild("CHASE_NODES") then
				for c,d in ipairs(b.CHASE_NODES:GetChildren()) do
					if Cloned_Rush.RUSH.DAMAGE.RUNNING.Value == true then
						local anglePart = d
						if anglePart then
							game.TweenService:Create(Cloned_Rush,TweenInfo.new(script.ENEMY_SPEED.Value,Enum.EasingStyle.Linear),{CFrame = anglePart.CFrame * CFrame.new(0,0,0)}):Play()
							task.wait(script.ENEMY_SPEED.Value)
						end
					else
					end
				end
			end
1 Like

Idk if that’s your intention.
I made it that any future rooms gets added to the loop and if the loop is done, no new rooms will get gone through. If you want them to get gone through, lemme know.

local Rush_DB = true
function Rush()
	if Rush_DB then Rush_DB = false

		if script.ENTITY_FOLDER.ACTIVE_RUSH.Value ~= nil then
			script.ENTITY_FOLDER.ACTIVE_RUSH.Value:Destroy()
		end


		script.EVENTS.LIGHTS_CONTROLLER:Fire("FLICKER")
		script.EVENTS.HIDING_HIGHLIGHT:Fire()
		task.wait(4)

		local Cloned_Rush = script.ENTITY_FOLDER.RUSH.Value:Clone()

		script.ENTITY_FOLDER.ACTIVE_RUSH.Value = Cloned_Rush

		Cloned_Rush.Parent = game.Workspace

		--game.Debris:AddItem(Cloned_Rush,20)


		Cloned_Rush.RUSH.CHASE:Play()
		Cloned_Rush.RUSH.CHASE_INNER:Play()

		local SPAWN_ROOM_NUMBER = script.ROOM_AMOUNT.Value -6

		local SPAWNROOM = script.ACTIVE_ROOMS_FOLDER.Value:FindFirstChild(SPAWN_ROOM_NUMBER)

		Cloned_Rush.CFrame = script.SPAWN_ROOM.Value:FindFirstChild("END").CFrame

		task.wait(4)

		local activeRoomsChildren = script.ACTIVE_ROOMS_FOLDER.Value:GetChildren()
		--local alreadyMovedTo = {}

		script.ACTIVE_ROOMS_FOLDER.Value.ChildAdded:Connect(function(child)
			table.insert(activeRoomsChildren, child)
		end) -- adds the future children to the existing table
		
		for idx,b in pairs(activeRoomsChildren) do
			--table.insert(alreadyMovedTo,b)
			if b:FindFirstChild("CHASE_NODES") then
				for c,d in ipairs(b.CHASE_NODES:GetChildren()) do
					if Cloned_Rush.RUSH.DAMAGE.RUNNING.Value == true then
						local anglePart = d
						if anglePart then
							game.TweenService:Create(Cloned_Rush,TweenInfo.new(script.ENEMY_SPEED.Value,Enum.EasingStyle.Linear),{CFrame = anglePart.CFrame * CFrame.new(0,0,0)}):Play()
							task.wait(script.ENEMY_SPEED.Value)
						end
					end

					--[[task.wait()

					if #script.ACTIVE_ROOMS_FOLDER.Value:GetChildren() > #script.ACTIVE_ROOMS_FOLDER.Value:GetChildren() and idx >= #script.ACTIVE_ROOMS_FOLDER.Value:GetChildren() then
						task.wait(script.ENEMY_SPEED.Value)
						
						local done = 0
						
						for c,d in pairs(script.ACTIVE_ROOMS_FOLDER.Value:GetChildren()) do
							if not table.find(alreadyMovedTo,d) then
								if b:FindFirstChild("CHASE_NODES") then
									for e,f in ipairs(d.CHASE_NODES:GetChildren()) do
										if Cloned_Rush.RUSH.DAMAGE.RUNNING.Value == true then
											local anglePart = f
											if anglePart then
												game.TweenService:Create(Cloned_Rush,TweenInfo.new(script.ENEMY_SPEED.Value,Enum.EasingStyle.Linear),{CFrame = anglePart.CFrame * CFrame.new(0,0,0)}):Play()
												task.wait(script.ENEMY_SPEED.Value)
											end
										end
									end
								end
							end
						end
					end]]
				end
			end
		end

		if script.ENTITY_FOLDER.ACTIVE_RUSH.Value ~= nil then
			if script.ENTITY_FOLDER.ACTIVE_RUSH.Value.RUSH.RUNNING.Value == true then
				script.ENTITY_FOLDER.ACTIVE_RUSH.Value:Destroy()
			end
		end

		Rush_DB = true
	end
end

If my method doesn’t work, I could try someone else’s method and credit them.

yes i want the new rooms to be gone trough too :smiley:

1 Like

i am trying out this method rooght now the info if it works will be given to you asap

1 Like

okay so this works but when he reached the last room he is stuck instead of disappearing like it was intended

1 Like