EDIT: Fixed, see below for the lines that fixed my script:
local speed = npc.Humanoid.Running:wait() if speed ~= 0 then repeat speed = npc.Humanoid.Running:wait() until speed == 0 end
Hi guys, I was wondering how I could check if a Humanoid arrives at a WalkToPoint set by the MoveTo function. I need this so I can begin re-moving my NPC when they arrive at their destination to give a sense of movement.
I have tried making it so it waits until the torso's X position equals the destination's X position, but this doesn't work as the Humanoid can sometimes overshoot it and be a few decimal places away from it.
Here is my current script, without waiting for the Humanoid to arrive at their destination:
local region = require(game.ServerScriptService:WaitForChild("RegionScript")) --ModuleScript that generates a random position when RandomiseLocation is called. local paths = game.Lighting.Paths:GetChildren() local npc = script.Parent npc:WaitForChild("Humanoid") npc:WaitForChild("Torso") while true do wait(2) local rand = math.random(1,#paths) local randLoc = region:RandomiseLocation(paths[rand]) print(randLoc.X, randLoc.Y, randLoc.Z) npc.Humanoid:MoveTo(randLoc) end
Any help is appreciated, thanks!
http://wiki.roblox.com/index.php?title=Running they stop walking when the speed is 0.
The MoveToFinished
event of Humanoid fires when a MoveTo function is, well, finished.
Exactly what you want(:
Usage;
local region = require(game.ServerScriptService:WaitForChild("RegionScript")) local paths = game.Lighting.Paths:GetChildren() local npc = script.Parent npc:WaitForChild("Humanoid") npc:WaitForChild("Torso") while wait(2) do local rand = math.random(1,#paths) local randLoc = region:RandomiseLocation(paths[rand]) print(randLoc.X, randLoc.Y, randLoc.Z) npc.Humanoid:MoveTo(randLoc) --Wait until it's finished npc.Humanoid.MoveToFinished:wait() print'MoveTo finished' end