How to do GetPartBoundsInBox()

Hello, I coded a script that checks if there is something in bounds. My issue is for some reason its counting itself as a part in bounds.

Note: Current is a model with lots of parts inside of it and I want it so the script ignores everything inside current.

Here is my code:

local current = script.Parent -- a model
local cframe = current:GetPivot()
local params = OverlapParams.new({current:GetDescendants()},Enum.RaycastFilterType.Blacklist,1,"Default")
local Checker = workspace:GetPartBoundsInBox(cframe, Vector3.new(5,5,5), params)
if #Checker == 0 then
  print("Run code")
else
  warn("denied request because something was in the way" )
  warn(Checker)
end

It always detects something in the way since it detects itself. I can even see it in the

warn(Checker)

that the parts are being picked up
image

1 Like

OverlapParams.new doesn’t take any arguments, you need to manually assign the properties:

local overlapParams = OverlapParams.new()
overlapParams.FilterDescendantsInstances = current:GetDescendants()
overlapParams.FilterType = Enum.RaycastFilterType.Blacklist
overlapParams.MaxParts = 1
2 Likes

To solve the issue of the script counting itself as part within bounds, you should add a condition to exclude β€œcurrent” in the script. For example, you could exclude all parts within β€œcurrent” in the creation of β€œparams” using this code:

local current = script.Parent -- a model
local cframe = current:GetPivot()
local children = current:GetChildren()
local exclusions = {}
for i, child in pairs(children) do
table.insert(exclusions, child)
end
local params = OverlapParams.new({exclusions}, Enum.RaycastFilterType.Blacklist, 1, "Default")
local Checker = workspace:GetPartBoundsInBox(cframe, Vector3.new(5,5,5), params)
if #Checker == 0 then
  print("Run code")
else
  warn("denied request because something was in the way" )
  warn(Checker)
end

getchildren() returns a table rferrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

explain more pls β€Ž β€β€β€Žβ€Ž β€β€β€Žβ€Ž β€β€β€Žβ€Ž β€β€β€Žβ€Ž β€β€β€Žβ€Ž β€β€β€Žβ€Ž β€β€β€Žβ€Ž β€β€β€Žβ€Ž β€β€β€Žβ€Ž β€β€β€Žβ€Ž β€β€β€Ž

doing

object:GetChildren()

returns a table. the fact you are able to loop through :GetChildren() means that its a table. by doing

local exclusions = {}
for i, child in pairs(children) do
table.insert(exclusions, child)
end

you are just looping through an existing table and adding it to another table

if you do

print(part:GetChildren())

it will print a table of all its children

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