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
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
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
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.
I did some testing around with a regular dummy and the rig 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.