Get amount of models inside an area?

Hello, I’m wondering if there’s any way to get the number of NPCs inside an area. I know it’s possible to get the number of parts using

local partsInArea = workspace:GetPartBoundsInBox(CFrame, Vector3, OverlapParams)

but is it possible to do the same with models? I’ve been searching the dev forum for answers but haven’t found anything. Thanks in advance.

You can do the exact same thing with that.

local partsInArea = workspace:GetPartBoundsInBox(CFrame, Vector3, OverlapParams)
local foundModels = {}
for _,v in pairs(partsInArea) do
   if v.Parent:IsA("Model") and not table.find(foundModels,v.Parent) then 
    table.insert(foundModels, v.Parent) 
   end
end
  • Make an array of currently retrieved models.
  • Use the part finder and check to make sure they are NPCs.
  • Add any found to the array, make sure there will be no duplicates.
1 Like

Instead of using v.Parent, you may wish to use Instance:FindFirstAncestorOfClass

2 Likes

thanks for the fast reply, I should’ve thought of that

thanks for the suggestion and fast reply