I was wondering how I would make a part than doesn’t allow certain NPCs to walk through. I’ve been searching for answers but I can’t find any online, so any feedback would be appreciated! Thanks!
You could use collision groups to do this.
The code below is from the wiki:
local PhysicsService = game:GetService("PhysicsService")
local obstacles = "Obstacles"
local greenObjects = "GreenObjects"
PhysicsService:CreateCollisionGroup(obstacles)
PhysicsService:CreateCollisionGroup(greenObjects)
PhysicsService:SetPartCollisionGroup(workspace.Obstacle1, obstacles)
PhysicsService:SetPartCollisionGroup(workspace.GreenBall, greenObjects)
PhysicsService:CollisionGroupSetCollidable(greenObjects, obstacles, false)
To create a collision group, you’re going to need to use the :CreateCollisionGroup() method from the PhysicsService. After that you can put a part in the collision group by using the :SetPartCollisionGroup() method. Right now the collision groups interact normally so you’re going to need to set how they should react using the :CollisionGroupSetCollidable() method. If you set CollisionGroupSetCollidable to true, they will collide, if it’s false they’ll act like cancollide = false.
1 Like
Thank you for your response! It helped a lot