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

Help With Moving A NPC?

Asked by
Scootakip 299 Moderation Voter
8 years ago
Bot.Humanoid:MoveTo(Pos)

This is part of my script for programming an NPC. Is it possible to make it so that it waits until Bot makes it to Pos before continuing on with the script, or am I going to have to figure out a way of doing this myself. I've already tried to fix this by putting it in a function rather than its own line of code by itself, but that didn't help.

0
repeat wait() until Bot.Torso.Position == Pos? TheDeadlyPanther 2460 — 8y

1 answer

Log in to vote
2
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

I would calculate how long it should take to walk there, wait that long, and if they still aren't there, recalculate and wait the new time until they arrive.

Bot.Humanoid:MoveTo(Pos)
while(Bot.Torso.Position-Pos).magnitude<5 do
    wait((Bot.Torso.Position-Pos).magnitude/Bot.Humanoid.WalkSpeed)
end

Give a range for how close it should be before it "arrives," because it isn't going to be exactly in that position.

0
Oh my goodness thank you so much for this. I never would've figured it out myself! Scootakip 299 — 8y
Ad

Answer this question