How to exclude player in GetPartBoundsInBox()?

Hello, I have this code which forms a bounding box around the area I the player builds a part to check if something is in the way. An issue is that it considers players to be objects and doenst allow it through.

I tried solving this by adding the plrs character to the blacklist (however I might have to do a for loop on all player’s characters so other players cant get in the way) but I need to get this working first.

Here is my code which blacklists the building players character (is serverside remote event, unknown variables are defined elsewhere but are self expanatory.)

--// Variables
local filterObjects = plr.Character:GetDescendants()
local boxPosition = CFrame.new(Vector3.new(Pos.X, 5, Pos.Z))
local params = OverlapParams.new(filterObjects,Enum.RaycastFilterType.Exclude,2,"Default")

--// Code
plr.Character:PivotTo(boxPosition) -- To test if it includes
local objectsInSpace = workspace:GetPartBoundsInBox(boxPosition,Vector3.new(4.5,4.5,4.5),params)
print(objectsInSpace) -- Outputs the character
2 Likes

From the documentation:
FilterDescendantsInstances: array | An array of objects whose descendants is used in filtering candidates.

The filterObjects should be just plr.Character. It will handle the :GetDescendants() part automatically. I think it may ignore the objects directly in the array, so by changing it to just plr.Character, it should fix your issue

OverlapParams.new() doesn’t take any parameters, you have to set it’s properties after creating new params like so:

local params = OverlapParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = filterObjects
params.MaxParts = 2

etc...

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.