How do you make a model only collide with specific objects?

The title says it all. So basicly I need help making specific objects to only be able to collide with a specific model / group of parts. The reason why? Thats a story for another time.

You can make use of Collision Groups via PhysicsService or the collision group editor in studio.

Edit:
To find the Collision Groups editor in studio, go to models and look for “Collision Groups”

An example of coding a collision group would be like this

local PhysicsService = game:GetService("PhysicsService")
local CollisionGroup = PhysicsService:CreateCollisionGroup("CollisionGroupName")

To make two groups not collide with each other, do this

PhysicsService:CollisionGroupSetCollidable("CollisionGroup","AnotherCollisionGroup",false) 

false to make them non collidable or true to make them collidable

To give parts a collision group, you could use this method

for i,v in ipairs(Model:GetDescendants()) do
    if v:IsA("BasePart") then
        v.CollisionGroupId = PhysicsService:GetCollisionGroupId("CollisionGroup")
    end
end

Note:
It is important to remember that there is a max amount of collision groups which is 32, it is best to wrap code that creates collision groups in a pcall. Also collision groups cannot have the same name.

5 Likes

What do you put in the quotation marks?

The name of the collision group.

1 Like

Is 32 the max per game? Or per group of parts?

The limit for collision groups is 32 per game. You can check with this function

2 Likes