[RESOLVED] My pathfinding script is not working? Any ideas why?

I am making a Camping inspired game, and tried to make a NPC names explorer move. When I run the game the NPC just randomly walks in the opposite direction I want it to, instead of the Point1 and Point2 system I have setup. Any ideas?

local NPC = game.Workspace.Explorer

debounce = true

wait(2)
NPC.Humanoid:Move(game.Workspace.Point1.Position)
NPC.Humanoid.MoveToFinished:Wait(5)
wait(5)
NPC.Humanoid:MoveTo(game.Workspace.Point2.Position)
NPC.Humanoid.MoveToFinished:Wait(5)
wait(5)

end

Please help me fix this, thanks George.

I think pathfinding is something different.
Also while moving to the first point you wrote :Move Instead of :MoveTo.
That’s probably why.

local NPC = game.Workspace.Explorer

debounce = true

wait(2)
NPC.Humanoid:MoveTo(game.Workspace.Point1.Position)
NPC.Humanoid.MoveToFinished:Wait()
wait(5)
NPC.Humanoid:MoveTo(game.Workspace.Point2.Position)
NPC.Humanoid.MoveToFinished:Wait()
wait(5)

end

When using .MoveToFinished:Wait(), the numbers in the parenthesis do nothing. The added :Wait() means that your code is yielding until the NPC finishes moving.

I watched a tutorial on how to make a game similar to camping for scripts etc, and he said to script the pathfinding, I did the script and it did not work. I adjusted it it did not work.

I tried doing what you suggested, still broken. Thanks for your time however,

1 Like

Path Finding is using the path finding service, this is just using the moveTo function. Also when you typed in Move To instead of move, it still moved in the opposite direction?

1 Like

How could I fix the issue I am really confused… Sorry. :pensive:

It’s stopped moving altogether.

Did it print an error in the output? You probably made a typo. Make sure you did “MoveTo:”

local NPC = workspace

debounce = true

wait(2)
NPC.Humanoid:MoveTo(game.Workspace.Point1.Position)
NPC.Humanoid.MoveToFinished:Wait()
wait(5)
NPC.Humanoid:MoveTo(game.Workspace.Point2.Position)
NPC.Humanoid.MoveToFinished:Wait()
wait(5)

I forgot to catch some errors

  • Game.Workspace.Explorer does not exist. You just have to type Game.Workspace, or workspace.
  • The end at the bottom of your code isn’t necessary.
  • What are you using debounce for?

I fixed it now anyway!! It was nothing to do with the script, the script worked fine but the thing I put at the start was wrong lol.

Instead of debounce = true

It should of been while true do.

Thanks!!

The part where I messed up was the debounce part, I fixed it now it should of been while true do. Thanks for your help resolving the problem! :slight_smile:

1 Like

i’m pretty sure everyone had that feeling of getting frustrated over an “error”, only for it to be an oversight lol.

anyways, YW.

Lol, yeah the reason why it messed up was because there was an “end” in the bottom of the script, it didn’t have anything to end, so it was just floating in there and caused an error. Now that you typed while true do, it had something to end, and didn’t throw an error. But the “Move” instead of “MoveTo” was also definitely an error.

2 Likes