Make NPC not collide with players?

There are a few problems and optimizations with your code:

  • You have to define setCollisionGroupsRecursive before you can use it in its own function. It will error otherwise, I think. Correct me if I’m wrong.
  • You can set the collision group of a part’s descendants using Part:GetDescendants() instead of a recursive Part:GetChildren(), so you would not even have to use the previous optimization.
  • You might want to use :IsA("BasePart") instead of :IsA("Part"), since this may be causing some parts that are still collidable but not of class Part to not have their collision groups properly set.
local function setCollisionGroups(object,isnpc)
    local collGroup = isnpc and npcGroup or plrg
    for _,part in ipairs(object:GetDescendants()) do
        if part:IsA("BasePart") then
            phys:SetPartCollisionGroup(part,collGroup)
        end
    end
end

There is a visual editor for collision groups provided by Studio. The devforum thread that announced it is here. I believe it is in Model > Advanced > Collision Groups, the page on the dev wiki for navigating the Model tab is here. You will be able to modify which collision groups will collide more easily there.

When you see the visual editor

Collision groups for parts are managed solely by their CollisionGroupId property, 0 is for the first collision group, regardless of name, 1 is for the next group down, and so on. This can be used to set collision groups from the part’s properties instead of through PhysicsService.

I hope that helps, I feel like I’m just spitting out information though…

3 Likes