Pathfinding problem!

Does any one know what the problem is with this script?

local part = script.Parent
local pathFinder = game:GetService("PathfindingService")

local path = pathFinder:CreatePath()

while true do

	path:ComputeAsync(part.Position, workspace.EndingForPart.Position)

	for i, wayPoint in pairs(path:GetWaypoints()) do
		part.Humanoid:MoveTo(wayPoint.Position)

		if wayPoint.Action == Enum.PathWaypointAction.Jump then
			part.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		end

		part.Humanoid.MoveToFinished:wait()	
	end

end

I have a humanoid in the part btw.

What problem are you observing with this script?

nothing it does literly nothing

You’re sure this script is running? Also, is it a server script?

yes it is a server script inside the part

does the npc have anchored humanoidrootpart?

it doesnt have a humanoid root part its a part

why are u using moveto and movetofinished if its just a part with no limbs? use tweenservice. or allignposition & allingorientation

byt it needs to find the way to it and walk around stuff

said it, allignposition and allingorientation, you cannot make a object move unless if the part is called HumanoidRootPart and has a humanoid.

but that s not in a real npc so why does it have to be in a part

parts don’t have humanoids, so using part.Humanoid:MoveTo() doesn’t do anything and causes it to break. @pumpkyrofl is saying to use bodymovers to move the part, or use tweenservice to CFrame the part manually as parts do not have MoveTo() and can’t move by themselves.

Based on the provided script, it appears to be a pathfinding script that continuously computes a path for a humanoid to move towards a specific endpoint. However, there are a few potential issues with the script:

  1. The script is in an infinite loop with no way to exit. This may cause performance issues and can potentially crash the game.
  2. The path is being computed every iteration of the loop, which can also cause performance issues.
  3. There is no check to see if the pathfinding actually found a valid path. If a path cannot be found, the script will still continue to execute.

Here are some potential solutions to these issues:

  1. Add a condition to break out of the loop, such as a boolean value that can be set to false when the script needs to stop.
  2. Compute the path only when necessary, such as when the endpoint has moved or the humanoid has moved a certain distance from the previous endpoint.
  3. Check the result of the pathfinding computation to see if a valid path was found, and handle the case where no path was found accordingly.

Overall, without more context on what the script is supposed to do and what the desired behavior is, it is difficult to provide a more specific solution.

1 Like