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.)
: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
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
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.