Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Im am trying to make a npc move with pathfinding service, but it wont move, any know why?




local dummy = game.Workspace.Dummy:WaitForChild("HumanoidRootPart")
local human = dummy:WaitForChild("Humanoid")
local point = game.Workspace.Part1
local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath()
path:ComputeAsync(dummy.HumanoidRootPart.Position, point.Position)
local waypoints = path:GetWaypoints()

for _, waypoint in pairs(waypoints) do
	local part = Instance.new("Part")
	part.Shape = "Ball"
	part.Material = "Neon"
	part.Size = Vector3.new(0.6, 0.6, 0.6)
	part.Position = waypoint.Position
	part.Anchored = true
	part.CanCollide = false
	part.Parent = game.Workspace

	human:MoveTo(waypoint.Position)
	human.MoveToFinished:Wait()
end


4 comments

0

is your dummy anchored? there is no issue in the script, so you might wanna check that.

0

its unanchored

0

It's something with the dummy, I tested it and it worked

0

ok

1 answer

✓ Accepted answer

The pathfinding service only works if the humanoid has somewhere to move to, and it seems like you tell the humanoid to move to what position, therefore the script doesn't know what the destination is. After your in pairs loop, add a human:MoveTo(point.Position) and it should work.

local dummy = game.Workspace.Dummy:WaitForChild("HumanoidRootPart")
local human = dummy:WaitForChild("Humanoid")
local point = game.Workspace.Part1
local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath()
path:ComputeAsync(dummy.HumanoidRootPart.Position, point.Position)
local waypoints = path:GetWaypoints()

for _, waypoint in pairs(waypoints) do
    local part = Instance.new("Part")
    part.Shape = "Ball"
    part.Material = "Neon"
    part.Size = Vector3.new(0.6, 0.6, 0.6)
    part.Position = waypoint.Position
    part.Anchored = true
    part.CanCollide = false
    part.Parent = game.Workspace

    human:MoveTo(waypoint.Position)
    human.MoveToFinished:Wait()
end

human:MoveTo(point.Position)

1 comment

0

Ok, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.