Super loop making trouble

hello. i got this code and i want it to break if all children of the ROOMS_FOLDER got the value in it.
how would i do so?

		while true do
			for a,b in pairs(script.ACTIVE_ROOMS_FOLDER.Value:GetChildren()) do
				if Cloned_Rush.RUSH.DAMAGE.RUNNING.Value == true then
					if not b:FindFirstChild("WeWentTroughThisAlready") then
						local GoneTroughVal = Instance.new("BoolValue")
						GoneTroughVal.Parent = b
						GoneTroughVal.Name = "WeWentTroughThisAlready"
						if b:FindFirstChild("CHASE_NODES") then
							for c,d in ipairs(b.CHASE_NODES:GetChildren()) do
								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
						end
					else
					end
				end
			end
		end

how would i do so? pls help

2 Likes

Try this.

while true do
    local allChildrenProcessed = true
    
    for _, room in pairs(script.ACTIVE_ROOMS_FOLDER.Value:GetChildren()) do
        if Cloned_Rush.RUSH.DAMAGE.RUNNING.Value == true then
            if not room:FindFirstChild("WeWentTroughThisAlready") then
                allChildrenProcessed = false
                
                local GoneTroughVal = Instance.new("BoolValue")
                GoneTroughVal.Parent = room
                GoneTroughVal.Name = "WeWentTroughThisAlready"
                
                if room:FindFirstChild("CHASE_NODES") then
                    for _, node in ipairs(room.CHASE_NODES:GetChildren()) do
                        local anglePart = node
                        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
    
    if allChildrenProcessed then
        break
    end
end

The break function will fully stop the loop if all players were processed.

1 Like

WHY are we talking about PLAYERS now? i was talking about children of the folder.

2 Likes

im trying to go trough all rooms, NOT just trough all NODES

2 Likes

Sorry I’m writing multiple scripts at once, ignore that little error.

while true do
    local allChildrenProcessed = true
    
    for _, room in pairs(script.ACTIVE_ROOMS_FOLDER.Value:GetChildren()) do
        if Cloned_Rush.RUSH.DAMAGE.RUNNING.Value == true then
            if not room:FindFirstChild("WeWentTroughThisAlready") then
                allChildrenProcessed = false
                
                local GoneTroughVal = Instance.new("BoolValue")
                GoneTroughVal.Parent = room
                GoneTroughVal.Name = "WeWentTroughThisAlready"
                
                if room:FindFirstChild("CHASE_NODES") then
                    for _, node in ipairs(room.CHASE_NODES:GetChildren()) do
                        local anglePart = node
                        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
    
    if allChildrenProcessed then
        break
    end
end
1 Like

this aint gonna work tho because everytime u run the loop u reset the allchildrenprocessed value lol

1 Like

never mind i just realised smth thanks ill try that out

2 Likes
local allChildrenProcessed = true

while true do
    for _, room in pairs(script.ACTIVE_ROOMS_FOLDER.Value:GetChildren()) do
        if Cloned_Rush.RUSH.DAMAGE.RUNNING.Value == true then
            if not room:FindFirstChild("WeWentTroughThisAlready") then
                allChildrenProcessed = false
                
                local GoneTroughVal = Instance.new("BoolValue")
                GoneTroughVal.Parent = room
                GoneTroughVal.Name = "WeWentTroughThisAlready"
                
                if room:FindFirstChild("CHASE_NODES") then
                    for _, node in ipairs(room.CHASE_NODES:GetChildren()) do
                        local anglePart = node
                        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
    
    if allChildrenProcessed then
        break
    end
end

maybe try and put the value on the outfit of the loop

this versaion actuallyworks all i need now is deleting all values after done going troug

1 Like

Have you tried resetting the value on the line before the break function?

1 Like

no. im doing it after the break end and i hope it works wish me luck lol

1 Like
local allChildrenProcessed = true
local values = {}

while true do
    for _, room in pairs(script.ACTIVE_ROOMS_FOLDER.Value:GetChildren()) do
        if Cloned_Rush.RUSH.DAMAGE.RUNNING.Value == true then
            if not room:FindFirstChild("WeWentTroughThisAlready") then
                allChildrenProcessed = false
                
                local GoneTroughVal = Instance.new("BoolValue")
                GoneTroughVal.Parent = room
                GoneTroughVal.Name = "WeWentTroughThisAlready"

                table.insert(values, GoneTroughVal)
                
                if room:FindFirstChild("CHASE_NODES") then
                    for _, node in ipairs(room.CHASE_NODES:GetChildren()) do
                        local anglePart = node
                        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
    
    if allChildrenProcessed then
        break
    end
end

for _, value in values do
   value:Destroy()
   value = nil
end
values = nil

we are so close to the solution… the only problem is that with my version he infinitely does this cycle.

1 Like

are you fr right now? does this work???

1 Like

There is only one way to find out if it does or not…

well where youre right there youre right man

1 Like

that gave me a stroke reading that

oventually you just confirmed that what i wrote would reach the expected reaction

1 Like

that’s because allChildrenProcessed never becomes true meaning the loop goes forever