AI Pathfinding script does not move the bot

Hello! I’m trying to create a pathfinding script to have a bot NPC follow random waypoint parts, but he just stays still and I’m not sure why. No errors in output.

Code:

local Bot = script.Parent
local Humanoid = Bot.Humanoid

local PathfindingService = game:GetService("PathfindingService")

local function GetPath(Destination)
	local Parameters = {
		["AgentHeight"] = 6,
		["AgentRadius"] = 3.47,
		["AgentCanJump"] = true
	}
	local Path = PathfindingService:CreatePath(Parameters)
	Path:ComputeAsync(Bot.HumanoidRootPart.Position, Destination.Position)
	return Path
end

local function WalkTo(Destination)
	local Path = GetPath(Destination)
	for Index, Waypoint in pairs(Path:GetWaypoints()) do
		Humanoid:MoveTo(Waypoint.Position)
		Humanoid.MoveToFinished:Wait()
	end
end

local function StartPatrol()
	local Waypoints = workspace.Waypoints:GetChildren()
	local RandomWaypoint = math.random(1, #Waypoints)
	WalkTo(Waypoints[RandomWaypoint])
end

while wait(.5) do
	StartPatrol()
end

The script works fine for me. Did you unanchor the HumanoidRootPart for your model? If there’s no errors then I think that would be the only reason.

The HumanoidRootPart is meant to be anchored? Would that not restrict the movement entirely?

When I was testing if the HumanoidRootPart was anchored the model wouldn’t be able to move at all so I just unanchored it and surprisingly the script ran fine. Well I didn’t create a model I just inserted a player and it worked so- ye

Hm. I’ve narrowed it down to this line:

using print debugging.

Not sure why, though?

Try checking the walkspeed / the parts inside the model if they’re anchored etc

None of the parts are anchored, and I’ll check the bot WalkSpeed now.
WalkSpeed is > 0 so it should be moving.

Mind sending a screenshot of the explorer? For the waypoints

image
Just a model in the workspace.

Here’s a video of my studio the script works fine for me after I unachored pretty much everything in the player cause it should still stay attached if it was welded correctly :confused:

It’s so confusing. It’s all welded correctly too, I just can’t comprehend why it isn’t moving. :thinking:

maybe you could send a place file?

Is every single part unachored then? If it’s welded it shouldn’t fall apart but if its anchored it won’t be able to actually move.

This includes any like handles for hats.

Yep, all unanchored. I tried it with a regular dummy and the same thing happens.

underneath this line:

Path:ComputeAsync(Bot.HumanoidRootPart.Position, Destination.Position)

can you add

print(Path.Status)

Adding the print will show you the status of the created path in your output window. If it doesn’t say Enum.PathStatus.Success then there is a problem with Path creation.


It’s fine I don’t think the issues within the script.

I did some testing around with a regular dummy and the rig image is the same as a regular player, The reason why it didn’t work though was most likely because the dummys humanoid has everything set to 0. If walkspeed was changed it should run perfectly fine and I think it would be a rig issue.

image

The WalkSpeed is enough to move, though? :thinking: image