OverlapParams.new() Is not working

local params = OverlapParams.new()
params.FilterDescendantsInstances = {previousBB} -- A part outside the function
params.FilterType = Enum.RaycastFilterType.Include

task.wait()
	
local touching = workspace:GetPartsInPart(previousBB, params)
print(touching.Name) -- This outputs "nil"

if touching.Name == "BoundingBox" then
	-- more script here... (it doesn't matter)
end

I’m trying to determine if the previousBB is touching any part called “BoundingBox” and if so, it would run the script inside the if statement.

The problem I’m facing is that whenever this runs, the print outputs “nil”, when the whole idea of this script is determine the name of the part to know if it’s called a “BoundingBox” or not.

(All the tutorials I’ve seen use a while loop, but that wouldn’t work with what I’m trying to do. I’m basically trying to generate a random grid-like room layout. The loop wouldn’t work because it is only getting spawned in, and then it checks if it touches any parts called “BoundingBox”. If it does, it will remove the “Room” and try again with a different type of room.)

How do I overcome this issue?

:GetPartsInPart() returns a table, not an instance. You need to iterate over the table and check the name of the instances within it

2 Likes

:GetPartsInPart returns an array so you cant do touching.Name. What you can do is loop through the array like this and check if one of the parts’ name is “BoundingBox”:

local params = OverlapParams.new()
params.FilterDescendantsInstances = {previousBB} -- A part outside the function
params.FilterType = Enum.RaycastFilterType.Include

task.wait()

local touching = workspace:GetPartsInPart(previousBB, params)
print(touching)

for _, boundingBox in pairs(touching) do
	if boundingBox.Name == "BoundingBox" then
		-- more script here... (it doesn't matter)
		
		break
	end 
end
2 Likes

Would you be able to write that out for me? (This is basically my first time working is OverlapParams, and I have no idea what to do)

the code @Bikereh gave should work

2 Likes

It doesn’t print “nil” anymore, but it also doesn’t print anything.
It also achieves the same result as last time.

1 Like

this is making it so that only previousBB can be found as a touching part, but that is thesame part that you are querying, so the touching table will always be empty
try changing it to
params.FilterType = Enum.RaycastFilterType.Exclude

2 Likes

Okay, this changed it so that it actually prints the names of the parts.
There are still errors, but it has to do with my scripting within the if statement.

Thanks!

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