So I'm trying to make an NPC walk to a point using pathfinding, but then I noticed I would get an error if the NPC is trying to walk through a union. The union is a room with an entrance created by a NegatePart, and it lets me walk through it. I think my script though thinks my room is completely blocked off and ignores the entrance.
What I need help on is how to make my script ignore the union, or walk through the entrance with no problem.
If you want to look at the script I'm using for pathfinding, here it is :
while wait(1) do path = game:GetService('PathfindingService'):FindPathAsync(script.Parent.HumanoidRootPart.Position, game.Workspace.NPCEscapePart.Position) if path.Status == Enum.PathStatus.Success then print('Success!') else script.Parent.Humanoid.WalkToPoint = Vector3.new(-89, 1.5, 0) --Directly set WalkToPoint when pathfinding won't work warn('Error! Cannot find valid path for NPC.') end local points = path:GetWaypoints() for i = 2, #points do local waypoint = points[i] local dest = waypoint.Position script.Parent.Humanoid:MoveTo(dest) if waypoint.Action == Enum.PathWaypointAction.Jump then script.Parent.Humanoid.Jump = true end local reached = script.Parent.Humanoid.MoveToFinished:Wait() if not reached then break end end end
This script works fine until it has to deal with unions. I don't know much about pathfinding too so sorry if this script is a little basic.
I also thought of 2 solutions to fix this, to directly set the WalkToPoint property in the NPC's humanoid to the part's position, or make several parts and also directly set the WalkToPoint property to the parts, and set the WalkToPoint to the next part once the NPC touches the part.
I then thought of some problems with the solutions. The NPC might get stuck somewhere as there's no pathfinding when I set the WalkToPoint, and I'm planning to make a place with lots of hallways and doors and corridors and etc, so making all the parts and setting the WalkToPoints is going to be painful to do.