Waypoint Script Trouble

  1. I want to have NPC patrolling in the background repeatedly, freeze and then continue (I have the freezing part down.

  2. The issue is for one I am no scripter so I obviously don’t know how big or small of a fix this is. But the issue is whenever the NPC is walking to the “wp1” etc… He doesn’t reach the part before turning to the second one, then the third and since its a hallway that’s connected to several other hallways, he is just hugging the wall before the first way point.


    As you can see they turn to the second way point “wp2” before they even reach “wp1”.

  3. I have tried different scripts I have made him faster but doing that ruins the way he’s supposed to act, as he is supposed to be slower then the normal speed. I have tried several different scripts to see if the outcome is different however its always the same.

local wp1 = game.Workspace.Sqaud1.WaySQ1.wp1 --wp1 stands for "waypoint1"
local wp2 = game.Workspace.Sqaud1.WaySQ1.wp2
local wp3 = game.Workspace.Sqaud1.WaySQ1.wp3
local wp4 = game.Workspace.Sqaud1.WaySQ1.wp4
local r = script.Parent.Humanoid

while true do
	r:MoveTo(wp1.MoveToFinish)
	wait(1)
	r:MoveTo(wp2.Position)
	wait(1)
	r:MoveTo(wp3.Position)
	wait(1)
	r:MoveTo(wp4.Position)
	wait(1)
end

Thank you,

1 Like

Instead of using wait(), consider using MoveToFinished:Wait(). This ensures that the next move to is not triggered until after it reaches the position it should be at.

local wp1 = game.Workspace.Sqaud1.WaySQ1.wp1 --wp1 stands for "waypoint1"
local wp2 = game.Workspace.Sqaud1.WaySQ1.wp2
local wp3 = game.Workspace.Sqaud1.WaySQ1.wp3
local wp4 = game.Workspace.Sqaud1.WaySQ1.wp4
local r = script.Parent.Humanoid

while true do
	r:MoveTo(wp1.Position)
	r.MoveToFinished:Wait()

	r:MoveTo(wp2.Position)
	r.MoveToFinished:Wait()

	r:MoveTo(wp3.Position)
	r.MoveToFinished:Wait()

	r:MoveTo(wp4.Position)
	r.MoveToFinished:Wait()
end

If you want, the code can also be compressed:

local WaypointHolder = game.Workspace.Squad1.WaySQ1 -- You have something named as Sqaud, when it should probably be Squad. Change it either here or the object's name
local Waypoints = {WaypointHolder.wp1, WaypointHolder.wp2, WaypointHolder.wp3, WaypointHolder.wp4}
local Humanoid = script.Parent.Humanoid
while true do
    for _, Waypoint in ipairs(Waypoints) do
        Humanoid :MoveTo(Waypoint.Position)
        Humanoid .MoveToFinished:Wait()
    end
end

Thank you for your response I have have one more question and its about this error. Is MoveToFinish some kind of physical part, or is it some kind of property within the waypoint part?
Screenshot (6)

It’s a property of the humanoid object. My code definitely accesses a humanoid so I’m not sure why yours doesn’t. Can you please send your current code?

If you used the first code, you need to edit this

to

	r:MoveTo(wp1.Position)

Oh I somehow missed that xD
I’ll fix it up in my original post. Thanks for pointing thhat out.

That should also fix your error btw.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.