Help with NPC-exclusive staff doors

Hello,
I want my NPC to be able to go through the staff door, but the players shouldn’t be able to. My staff door is collidable, so I wrote this script:

local physics = game:GetService('PhysicsService')
local collisionGroup = physics:CreateCollisionGroup('group')
local npsGroup = physics:CreateCollisionGroup('npcs')
physics:CollisionGroupSetCollidable('npcs','group',false)

local function main()
	for _, mainPart in pairs(workspace.Teacher:GetChildren()) do
		if mainPart:IsA('BasePart') then
			physics:SetPartCollisionGroup(mainPart,'npcs')
		end
	end
	
	for _, doorPart in pairs(workspace.StaffDoor:GetChildren()) do
		if doorPart:IsA('BasePart') then
			physics:SetPartCollisionGroup(doorPart,'group')
		end
	end
end

wait(math.random(3,5))
main()

However, my NPC cannot go through the door.
I appreciate help!

1 Like

Possibly my tutorial can help you https://www.youtube.com/watch?v=ClJpykt32YY it seems that you forgot to add doors to the collision group

What do you mean I forgot to add doors? That’s what I’m doing with this:

	for _, doorPart in pairs(workspace.StaffDoor:GetChildren()) do
		if doorPart:IsA('BasePart') then
			physics:SetPartCollisionGroup(doorPart,'group')
		end
	end

Yea but you dont set there state

Then what do I do?

physics:CollisionGroupSetCollidable(‘npcs’,‘group’,false)

That’s what I did:

physics:CollisionGroupSetCollidable('npcs','group',false)

Look at 4th line.

Any idea what my problem is? .