Can't iterate through FindPartsInRegion3?

I’m basically just trying to iterate through the table FindPartsInRegion3() creates. I’m creating the region on server start, and that part seems to be working perfectly fine.

However, for some reason when I try to iterate through the table, it just… wont work? The script literally just stops there and I have no idea why.

local event = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("near")
local within = false
local pos1, pos2, region
local plr 

for _,v in pairs(workspace.WorkoutEquipment:GetChildren()) do
	if v:FindFirstChild("headpoint") ~= nil then
	print("yuh")
		local headpoint = v:FindFirstChild("headpoint")
		pos1 = v.pos1.Position
		print(pos1)
		pos2 = v.pos2.Position --headpoint.Position + Vector3.new(2, 5, -10)
		print(pos2)
		region = Region3.new(pos1, pos2)
		print(tostring(region.Size).." This is the size of the region3")	
		--see region
		local part = Instance.new("Part", workspace)
		part.Name = "REGION"	
		part.CanCollide = false
		part.Anchored = true
		part.Transparency = .5
		part.CFrame = region.CFrame	
		part.Size = Vector3.new(math.abs(region.Size.X), math.abs(region.Size.Y), math.abs(region.Size.Z))
				
	end
end

while true do
	wait(1)
	print("lets get started")
	print(region.CFrame)
	for i,v in pairs(workspace:FindPartsInRegion3(region)) do -- stops here
		print("cool")
		if v.Parent:FindFirstChild("Humanoid") ~= nil then
			print("ok2")	
			plr = game.Players:GetPlayerFromCharacter(v.Parent)
			print(plr.Name)
			print("ok3")		
		end
	end
end

Everything after the pairs loop with the comment next to it doesn’t run. Any help is appreciated!

Can you send a screenshot of the output?

Does the while loop stop printing out “let’s get started”?

https://gyazo.com/8e3b8dc02ac1472c131104de0195ad52 and the loop does continue to keep printing.

It looks to me like you are creating multiple regions and setting them all to the same variable which means only the last region will work, I could be wrong though.

that might be the case for future entries to that “WorkoutEquipment” folder, but for the time being it only has one model in it. so, I don’t think thats cause.

Are you sure things are inside the region specified? If nothing inside the for loop prints it could be due to the fact that there is actually nothing in the region.

https://gyazo.com/945bc0dc9a9e8b575e76278f1f27474b not only does my player move through the region, but the region is created ontop of other parts(not above 20.) i’m pretty sure there is stuff within the region, either way let me check real quick.

well… it seems that there really isn’t anything within my region3…

if #workspace:FindPartsInRegion3(region) == 0 then
	print("there is none")
elseif #workspace:FindPartsInRegion3(region) < 0 then
	print("THERE IS STUFF IN HERE!")
end

https://gyazo.com/6085f20a9c14eb5aefc2a31ff9a08375 now the question is why is there nothing within my region3…?

It is possible that your region is too small, or mispositioned. Otherwise you may be waiting too long in your while loop.

I’ve checked to make sure that my region isn’t too small by printing its Size and checked its CFrame as well. I’ve also made sure to lower the wait time but to no avail, it deemed the same results https://gyazo.com/c38a707313224499f40d2b1bd6ad7bf2 any other solutions maybe?

Your region has negative size values? Perhaps that is the issue. Try:

local p1 = v.pos1.Position
local p2 = v.pos2.Position
local minPoint = Vector3.new(math.min(p1.x, p2.x), math.min(p1.y, p2.y), math.min(p1.z, p2.z))
local maxPoint = Vector3.new(math.max(p1.x, p2.x), math.max(p1.y, p2.y), math.max(p1.z, p2.z))
region = Region3.new(minPoint, maxPoint)

Sorry that it took a while to reply, but this made it work exactly the way I wanted it too. THANKS!!