How to use GetPartBoundsInBox

After reading the documentation, I’ve made this script:

local function checkObjectColiding(size, position, previewModel)
	local params = OverlapParams.new()
	params.RespectCanCollide = true
	params.FilterDescendantsInstances = {previewModel:GetDescendants()}
	local box = workspace:GetPartBoundsInBox(CFrame.new(position), size, params)
	print(box)
	if #box >= 1 then
		return false
	else
		return true
	end
end

however for some reason the box still returns object inside of itself:


image


image


I’m making a build system, and it should filter the preview object I am placing. so what did I do wrong?


image

1 Like

It’s enough to put the preview model alone (without :GetDescendants()) in FilterDescendantsInstances for all descendants to be evaluated. Try setting FilterType to Exclude explicitly.

its really weird because sometimes it works and sometimes it doesnt (just like before):

image

updated code:

local function checkObjectColiding(size, position, previewModel)
	local params = OverlapParams.new()
	params.RespectCanCollide = true
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances = {previewModel}
	local box = workspace:GetPartBoundsInBox(CFrame.new(position), size, params)
	print(box)
	if #box >= 1 then
		return false
	else
		return true
	end
end

Quite odd. I couldn’t reproduce the issue, everything works as it should with that code and different part properties. I don’t have a theory on what could be wrong. The only detected model member is that modelRoot, right?

We know that currently with ray- and shapecasting, if the rays start inside the part, that part won’t be considered, but that shouldn’t have anything to do with getting parts.

Would you consider sending a repo (you can send me a PM if you wish)?

Yes, only the model root is detected. I can try debugging some, let me know if you find anything.

also, the model root is only detected after I make the model go inside the player, then some time after that too.

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