'for i,v in pairs() do' function not working

Hello! Today im coding the SurfaceAmbience local script, what this script do? If you enter in some region it turning on ambience sound, if you leave, it turning off. But i got issue with ‘for i,v in pairs() do’ function. Basically he is skipping this function without any error.

Local Script: (Location: Game.StarterGui)

local soundManager = {}

for _, region in pairs(workspace.BRICKS.AreasRegions:GetChildren()) do --this function he skipping
	local info = {}
	local region3 = Region3.new(region.Position-(region.Size/2),region.Position+(region.Size/2))

	info.Region = region3
	info.Sound = script.Sounds:FindFirstChild(region.Name)
	info.VolumeOfSound = info.Sound.Volume

	table.insert(soundManager,info)
	
	print("Done")
end

print("Setting set up!")

task.wait(10)

game:GetService("RunService").RenderStepped:Connect(function()
	print("STEPPED RUNNING")
	for i, soundInfo in pairs(soundManager) do
		print("FOR I DO RUNNING")
	end
end)

image

I tried to fix this but it still skipping this. Also i noticed if i disable local script and enable it again, this function won’t skip. What should i do to fix this?

This means that

workspace.BRICKS.AreasRegions

Has no children (yet)

image
it is have and folder is not empty…

try this:

local soundManager = {}

local bricks = workspace:WaitForChild("BRICKS")
local AR = bricks:WaitForChild("AreasRegions")

while #AR:GetChildren() <=1 do
  task.wait(.5)
end

for _, region in pairs(AR:GetChildren()) do --this function he skipping
	local info = {}
	local region3 = Region3.new(region.Position-(region.Size/2),region.Position+(region.Size/2))

	info.Region = region3
	info.Sound = script.Sounds:FindFirstChild(region.Name)
	info.VolumeOfSound = info.Sound.Volume

	table.insert(soundManager,info)
	
	print("Done")
end

print("Setting set up!")

task.wait(10)

game:GetService("RunService").RenderStepped:Connect(function()
	print("STEPPED RUNNING")
	for i, soundInfo in pairs(soundManager) do
		print("FOR I DO RUNNING")
	end
end)

now it is working, thank you for this solution

Swap this:

while #AR:GetChildren() <=1 do
  task.wait(.5)
end

For this:

AR.ChildAdded:Wait()

and remove this:

print("Setting set up!")

task.wait(10)