:GetPartBoundsInBox Help

Hey everyone! I have tried to use :GetPartBoundsInBox multiple times, but cannot figure out how to actually operate it. Does anyone have any tips? Thanks!

6 Likes

GetPartBoundsInBox takes a CFrame for where you want the box to be and then a Vector3 for the size of the box. It then also takes OverlapParams, which work similarly to RaycastParams.

OverlapParams will take a table of objects, a filter type for these objects, the maximum amount of parts you want it to return and then a collision group that the search will take place in. The Collision group is important, as any parts set to not collide in this group will be ignored.

The function itself will return a table of the objects found in the box. I created a quick example for you to look at if you wish. This is a blacklist example where any objects in filterObjects will be ignored (in this case there are none).

local filterObjects = {}
local boxPosition = CFrame.new(0,0,0)
local boxSize = Vector3.new(10,10,10)
local maxObjectsAllowed = 10
local params = OverlapParams.new(filterObjects,Enum.RaycastFilterType.Blacklist,maxObjectsAllowed,"Default")
local objectsInSpace = workspace:GetPartBoundsInBox(boxPosition,boxSize,params)
print(#objectsInSpace)
24 Likes

In the API reference for OverlapParams, it’s stated that the constructor for the params doesn’t take any arguments, and the properties should be set separately.

So the code should be like this.

local params = OverlapParams.new()
params.CollisionGroup = "Default"
params.FilterDescendantsInstances = filterObjects
params.FilterType = Enum.RaycastFilterType.Blacklist
params.MaxParts = maxObjectsAllowed

Also it should be noted, in the case of performing boundary queries repeatedly, that you should reuse the params object, as all of its members can be changed on fly.

12 Likes