I’m trying to see if the player moves at all during an event. If the player moves, it works just fine, because MoveDirection.magnitude > 0.
The problem is, if I use MoveTo() on the player’s humanoid, this function doesn’t get triggered. I’m assuming because of it only sees user input as a movement.
What are some good ways to tell if the player is moved all? Regardless of user input?
MoveDirection is not updated when :MoveTo is used, so it can’t be used in this case.
The humanoid.Running event runs if the player moves at all, even if another player pushed them or something. If we only want it to react when the player themselves tries to move, humanoid.Running doesn’t work.
Very late to this, but you can use MoveDirection.magnitude by replicating MoveTo() using Move().
Set the angle of Humanoid:Move() to a CFrame.lookAt value. Then just repeat wait until the magnitude hits the part.
local Humanoid = script.Parent:WaitForChild("Humanoid")
local Torso = script.Parent:WaitForChild("Torso") -- If you're using R15, set Torso to LowerTorso.
local Destination = workspace:WaitForChild("Part")
local a = CFrame.lookAt(Torso.Position, Destination.Position)
Humanoid:Move(a.LookVector, false)
repeat
local m = (Torso.Position - Vector3.new(Destination.Position.X, Torso.Position.Y, Destination.Position.Z)).Magnitude
-- I only did this so the Y value of the Destination is the same as the torso. Feel free to replace the entire Vector3 with Destination.Position
print(string.format('Magnitude: %i', m)) -- This is optional, but I like to know details. :)
task.wait()
until m < 0.2 -- From what I know, the Magnitude of a position is somehow different based on angles. 0.2 is the only value that I know can support all of these angles.
Humanoid:Move(Vector3.new(0,0,0), false) -- Stops the humanoid from moving