I have an NPC that uses pathfinding service, and since pathfinding service ignores collision groups, I’m having to do a bit of a nasty workaround.
Rather than setting the NPC - Door collision group to false, I’m having to set every part in the doors to CanCollide off, then add a collision group between the doors and the player’s character and set it to true.
Issue is, the player can still walk right through the door.
Knowing me I likely missed something or forgot to add an important line but I’m really stumped here.
Here’s the script I’m using, it runs when the server starts.
There are no errors in the dev console.
local doors = workspace:WaitForChild("Facility_Doors")
local GroupName = "Doors"
local LocalName = "Players"
PhysicsService:CreateCollisionGroup(GroupName)
PhysicsService:CreateCollisionGroup(LocalName)
PhysicsService:CollisionGroupSetCollidable(GroupName, LocalName, true)
for _,v in pairs(doors:GetDescendants()) do
if v:IsA("BasePart") then
v.CanCollide = false
PhysicsService:SetPartCollisionGroup(v, GroupName)
end
end
doors.DescendantAdded:Connect(function(v)
if v:IsA("BasePart") then
v.CanCollide = false
PhysicsService:SetPartCollisionGroup(v, GroupName)
end
end)
for _,v in pairs(Players:GetPlayers()) do
if not v.Character then
v.CharacterAdded:Wait()
end
for _,v in pairs(v.Character:GetDescendants()) do
if v:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(v, LocalName)
end
end
v.Character.DescendantAdded:Connect(function(v)
if v:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(v, LocalName)
end
end)
end
Players.PlayerAdded:Connect(function(v)
v.CharacterAdded:Connect(function(c)
for _,v in pairs(c:GetDescendants()) do
if v:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(v, LocalName)
end
end
c.DescendantAdded:Connect(function(v)
if v:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(v, LocalName)
end
end)
end)
end)
Could all be avoided if PathfindingService respected collision groups, but here we are I guess.
Right now my explanation is that the CanCollide property is overriding the collision group.