How do I make it so only players cant go through a certain part?

Please correct me if this is the wrong category. I could not figure it out lol.

So basically I need to make it so the player cant go through a certain part, where as NPC’s can.

I know I would use Collison groups, but I could not figure them out!

So thanks!

I found an article on the Roblox Creator Documentation page which will guide you through Collision Groups:

1 Like

Players will not collide with that part. For example if you spawn NPC from toolbox it will collide with that part.

local physics = game:GetService("PhysicsService")
physics:RegisterCollisionGroup("PartCollisionGroup")
physics:RegisterCollisionGroup("Players")
function setCollision(part)
          if part:IsA("BasePart") then
                part.CollisionGroup = "Players"
         end
end
game:GetService("Players").PlayerAdded:Connect(function(plr)
       plr.CharacterAdded:Connect(function(char)
              char.DescendantAdded:Connect(setCollision)
              for i,v in pairs(char:GetDescendants()) do
                     setCollision(v)
              end
       end)
end)
local Part = Instance.new("Part",workspace)
Part.Anchored = true
Part.Position = Vector3.new(0,10,0)
Part.CollisionGroup = "PartCollisionGroup"
physics:CollisionGroupSetCollidable("PartCollisionGroup", "Players", false)
physics:CollisionGroupSetCollidable("Players","PartCollisionGroup", false)