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

Someone help me with this NPC Path script?

while true do

script.Parent.WalkToPoint = script.Parent.Parent.Parent.PointB.Position
wait(3)
script.Parent.WalkToPoint = script.Parent.Parent.Parent.PointA.Position
wait(3)
script.Parent.WalkToPoint = script.Parent.Parent.Parent.PointC.Position
wait(3)
script.Parent.WalkToPoint = script.Parent.Parent.Parent.PointD.Position
wait(3)
script.Parent.WalkToPoint = script.Parent.Parent.Parent.PointE.Position
wait(3)

end

Ok, so I obviously want the NPC to move to these paths.

But, for some reason, when the NPC is moving to say A to C, after about 3 seconds, the NPC starts to move to D without first reaching C!

Could someone help me to where the NPC will complete his path, and then move to the next point instead of just stopping midway?

Thanks!

2 comments

0

Check the Position of script.Parent using a repeat loop?

0

The position of script.Parent is in Workspace. Each of the points are parts.

1 answer

✓ Accepted answer

The humanoid will walk to D after three seconds, just like you told it to. It does not care if it already reached C, because it has new commands. You could fix this using a repeat loop, line Luna said, but it may make a difference based on the size of the brick

repeat 
	wait() 
until
	 script.Parent.Parent.Torso.Position == workspace.PointE.Position --This assumes that script.Parent is the Humanoid and script.Parent.Parent is is the character model. 

You could also use magnitude to check if the torso is a certain distance away from the part. This would be useful if the part's y position is above or below the torso's y position, and therefore they would never exactly equal eachother.

repeat 
	wait() 
until
	 (script.Parent.Parent.Torso.Position - workspace.PointE.Position).magnitude <= 5 --This assumes that script.Parent is the Humanoid and script.Parent.Parent is is the character model. 

Hope i helped!

2 comments

0

Yes, very. Thank you!

0

Np

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