Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I keep my npc from randomly stopping when going to a waypoint?

Hello. My npc is coded to go to one waypoint, and then another (the waypoints are 2 parts in a workspace folder called "waypoints")

He goes to the first waypoint just fine, but stops when almost reaching the second waypoint. Apparently its too far for him or something.

I don't know how to get him to the end. Help would be appreciated!

my code:

local npc = script.Parent local waypoints = workspace.Waypoints:GetChildren() local waypoint = 0

function move()

local choosing = waypoint + 1

local destination = waypoints[choosing]

npc:MoveTo(destination.Position)

npc.MoveToFinished:Wait()

nextstep()

end

function nextstep()

waypoint = waypoint + 1

if waypoint == 4 then

waypoint = 0

end

move()

end

1 answer

I think your problem is that you aren't putting it in a loop, so maybe try this:

local npc = script.Parent local waypoints = workspace.Waypoints:GetChildren() 
local waypoint = 0

while wait() do
function move()

local choosing = waypoint + 1

local destination = waypoints[choosing]

npc:MoveTo(destination.Position)

npc.MoveToFinished:Wait()

nextstep()

end

function nextstep()

waypoint = waypoint + 1

if waypoint == 4 then

waypoint = 0

end

move()

end
end

If that doesn't work, try doing this:

local npc = script.Parent local waypoints = workspace.Waypoints:GetChildren()
local waypoint = 0

local function nextstep()

waypoint = waypoint + 1

if waypoint == 4 then

waypoint = 0

end

move()

end

function move()

local choosing = waypoint + 1

local destination = waypoints[choosing]

npc:MoveTo(destination.Position)

npc.MoveToFinished:Wait()

nextstep()

end


Sorry if it doesn't work, I'm not really the best with scripting.

This discussion is preserved as it was. New answers, comments, and votes are closed.