Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does my Path-finding script not return any errors but it won't make the dummy move?

Asked by 3 years ago

I created a basic Path-finding script because it is my first time dealing with it. I created this as a base for testing. No errors are returned and the prints work fine. I inserted my avatar through the Load Character Plugin for the dummy, meaning that only HRP is anchored.

local PathFindingService = game:GetService("PathfindingService")
local Bone = script.Parent.HumanoidRootPart
local Human = script.Parent.Humanoid

local function GrabTarget()
    local playertable = game.Players:GetChildren()
    local target
    local targetmag
    for i, player in pairs(playertable) do
        local char = player.Character or player.CharacterAdded:Wait()
        local rootpart = char.HumanoidRootPart
        local mag = (rootpart.Position - Bone.Position).Magnitude
        print(mag)
        if target == nil or mag < targetmag then
            target = player
            targetmag = mag
        end
    end
    return target
end

wait(10)

local path = PathFindingService:CreatePath()
local togoto = GrabTarget()
print(togoto.Character.HumanoidRootPart.Position)
path:ComputeAsync(Bone.Position, togoto.Character.HumanoidRootPart.Position)

for i,waypoint in pairs(path:GetWaypoints()) do
    Human:MoveTo(waypoint.Position)
    Human.MoveToFinished:Wait()
end
0
unachor the hrp VerdommeMan 1479 — 3y
0
Thanks! ImmuneNexus 20 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

Well since that was the answer you can mark this as solved

Ad
Log in to vote
0
Answered by 3 years ago

VerdommeMan was correct. The HRP shouldn't be anchored.

Answer this question