I want to make an NPC to be able to walk through walls but im having an issue with making it happen. If anybody could help me, It would be really appreciated! By the way, the script is inside the NPC.
local ps =game:GetService("PhysicsService")
ps:CreateCollisionGroup("WallsGroup")
ps:CreateCollisionGroup("NPC")
for _,v in pairs(game.Workspace:GetChildren()) do
if v:IsA("BasePart") then
ps:SetPartCollisionGroup(v,"WallsGroup")
end
end
for _,npc in pairs(script.Parent:GetChildren()) do
for _,v in pairs(npc:GetDescendants()) do
if v:IsA("BasePart") then
ps:SetPartCollisionGroup(v,"NPC")
end
end
end
wait(2)
ps:CollisionGroupSetCollidable("WallsGroup", "NPC", false)
Is your script inside a single npc or a group of npcs? From the way your second loop is structured it looks like your script assumes its in a group of them. You probably also donât want to set every part in the workspace to be a wall, otherwise itâll result in your npcs falling through the floor.
Ideally, the script should be placed in the Server Script Service. If you simply move the script and the pointers (script.Parent) youâll achieve the same result.
From briefly running over your code, I donât see any issue with how the collision groups are being set etc. However what you need to make sure is that the pathfinding is actually recognising the doors as not existing - I am pretty certain that pathfinding will see a wall and assume that you cannot pass through the wall as it doesnât actually check if the wall is no collide.
Therefore please make sure your pathfinding has been given relevant modifiers so it can understand which objects can be passed through.
Now Iâm not just going to abandon youâŚ
Here is Roblox API documentation which actually explains passing through a door with Robloxâs pathfinding: