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

Someone help me with this NPC Path script?

Asked by 9 years ago
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!

0
Check the Position of script.Parent using a repeat loop? LunaScripter 80 — 9y
0
The position of script.Parent is in Workspace. Each of the points are parts. Tonitrua 20 — 9y

1 answer

Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

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!

0
Yes, very. Thank you! Tonitrua 20 — 9y
0
Np Perci1 4988 — 9y
Ad

Answer this question