#please help pathfinding

1 messages · Page 1 of 1 (latest)

quaint kayak
#

why is the npc teleporting instead of walking slowly it instantly move to the player , this is my script inside of the npc model:
the script is not full but i have the character limit, this is the part where its not working i think

while true do
    local target = GetClosestPlayer()
    if target then
        repeat task.wait() until target.Character or target.CharacterAdded:Wait()
        path = CreatePlayerPath(target)
        
        if path then
            waypoints = path:GetWaypoints()
            for _, waypoint in pairs(waypoints) do
                local part = Instance.new("Part")
                part.Position = waypoint.Position
                part.Size = Vector3.new(.5,.5,.5)
                part.Color = Color3.new(1,0,1)
                part.Anchored = true
                part.CanCollide = false
                part.Parent = workspace
                game.Debris:AddItem(part,.5)
                
                npc:MoveTo(waypoint.Position)
            end
            
        end
    else
        npc:MoveTo(npcHRP.Position)
        path = nil
        waypoints = nil
    end
    runservice.Heartbeat:Wait()
end
lethal kernel
# quaint kayak why is the npc teleporting instead of walking slowly it instantly move to the pl...

you didn't show the whole code so i'm guessing that npc is the model, not their humanoid. that's the first problem. the second problem is there's no waits in the loop through the waypoints you need to use humanoid.movetofinished. i'm guessing this is your first one so here's a guide on how to do pathfinding correctly: https://create.roblox.com/docs/characters/pathfinding

Pathfinding is the process of moving a character along a logical path to reach a destination.