Trouble with region3

Hi developers! Currently working on my first region3, which is kinda embarrassing because I’ve been scripting for around 2 years :sweat_smile: , But im trying to use FindAllPartsInReigon3() and it’s constantly saying that the test block is in the region, anyway here is the current code:

 local min = PreviewPart.Position - (0.5 * PreviewPart.Size)
local max = PreviewPart.Position + (0.5 * PreviewPart.Size)
local region = Region3.new(min, max)
			local PartsInReigon = workspace:FindPartsInRegion3(region, workspace.Baseplate, math.huge)
			for i,v in pairs(PartsInReigon) do
				print(v.Name)
			end

this is whats going wrong:


Any help is appreciated!

Just noticed I don’t set a position to it, do I have to? if so how do I do it?

The problem is, you’re running the code only once. Try connecting a function to the RunService.RenderStepped event and run the code in the function.

Hi syntqs, I did not post the full script because it has a lot of unnecessary parts but the script does get run constantly

Apologies, I haven’t paid attention to the video you’ve sent.

Try replacing that part of your code with this:

local min = PreviewPart.Position - Vector3.new(PreviewPart.Size.X/2,PreviewPart.Size.Y/2,PreviewPart.Size.Z/2)
local max = PreviewPart.Position + Vector3.new(PreviewPart.Size.X/2,PreviewPart.Size.Y/2,PreviewPart.Size.Z/2)

And I believe Region3 functions are deprecated. You should use the new spatial query feature.

The reason is that the PreviewPart is in the workspace, and the region is calculated by the PreviewPart's position, so the PreviewPart counts as “inside of the region”.

Consider blacklisting the PreviewPart so it does not get detected inside the region. I would recommend using FindAllPartsInRegion3WithIgnoreList to ignore the Baseplate and the PreviewPart in one line.

Change this:

local PartsInReigon = workspace:FindPartsInRegion3(region, workspace.Baseplate, math.huge)

To this:

local PartsInReigon = workspace:FindPartsInRegion3WithIgnoreList(region, {workspace.Baseplate, PreviewPart}, math.huge)

Make sure that the second parameter of FindPartsInRegion3WithIgnoreList is an array with instances to blacklist. Hope you find this helpful! :+1:

Workspace:FindPartsInRegion3 is deprecated. Use Overlap Params instead: Introducing OverlapParams - New Spatial Query API