Is there a way to get a model using overlaspeparam?

Hi im trying to find if its possible to get a model in using the overlaspeparam function . right now all what it gives me are only the parts and i can’t get the parts parent. I just want to know if it’d be possible to reference the parts parent (aka the model).

Any help would be appreciated.

Code:

local function getpartstouching(touchingpart:BasePart)
	local filter = OverlapParams.new()
	
	filter.FilterDescendantsInstances = {touchingpart}
	filter.FilterType = Enum.RaycastFilterType.Blacklist
	local cf, size = touchingpart.CFrame, touchingpart.Size
	return workspace:GetPartBoundsInBox(cf, size, filter)
end

while true do wait(.1)
	print(getpartstouching(script.Parent))
end

To get a list of models instead, you could loop through the list of parts and check their parent one by one.

local models = {}
-- Use a dictionary for a performant way to check whether a model is
-- already in the list
local alreadyAdded = {} 

for _, part in ipairs(getpartstouching(script.Parent)) do
    if part.Parent:IsA("Model") and not alreadyAdded[part.Parent] then
        table.insert(models, part.Parent)
        -- Set the value to true so that you don't add the same model
        -- twice
        alreadyAdded[part.Parent] = true
    end
end

print(models)
1 Like