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

How would I fix my NPC not moving with pathfinding?

Asked by 4 years ago

I have this code that is supossed to spawn an enemy and then move them towards a brick in the workplace. The NPC spawns just fine but it does not move at all and just stands there. I also get no error in the output.

local PathfindingService = game:GetService("PathfindingService")

        local Enemies = game:GetService("ServerStorage"):WaitForChild("Enemies")

        local SpawnPoints = {workspace:WaitForChild("SpawnPoints").SP1,
                      workspace:WaitForChild("SpawnPoints").SP2,
                      workspace:WaitForChild("SpawnPoints").SP3}

        local EndPoints = {workspace:WaitForChild("EndPoints").EP1,
                      workspace:WaitForChild("EndPoints").EP2,
                      workspace:WaitForChild("EndPoints").EP3}


        local ran = math.random(1,3)

        local RaiderClone = Enemies.Raider:Clone()
        RaiderClone.Parent = workspace
        RaiderClone.HumanoidRootPart.CFrame = SpawnPoints[ran].CFrame

        local path = PathfindingService:CreatePath()
        path:ComputeAsync(RaiderClone.UpperTorso.Position,workspace.EndPoints.EP1.Position)

        local Waypoints = path:GetWaypoints()

        for i,waypoint in pairs(Waypoints) do
            RaiderClone.Humanoid:MoveTo(waypoint.Position)
            RaiderClone.Humanoid.MoveToFinished:Wait(2)
        end

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago
local NPC = game.Workspace."npc name here"

while true do 
    wait()
    NPC.Humanoid:MoveTo(game.Workspace."insert part name u want the npc to go".Position)
    NPC.Humanoid.MoveToFinished:Wait()
    wait("insert time here")
    NPC.Humanoid:MoveTo(game.Workspace."insert part name u want the npc to go".Position)
    NPC.Humanoid.MoveToFinished:Wait()
    wait("instert time here")
    NPC.Humanoid:MoveTo(game.Workspace."insert part name u want the npc to go".Position)
    NPC.Humanoid.MoveToFinished:Wait()
    wait("insert time here")
end
0
Replace local spawn points and local end points and put this instead Shadic1270 136 — 4y
Ad

Answer this question