Issue with humanoid.MoveDirection, need help

Hey, So…

I have a script where I use humanoid.MoveDirection to play an animation based on the players position. (Code provided.)

But when I use humanoid:MoveTo() it doesn’t play said animation. No errors, nothing.

local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character
local humanoid = character.Humanoid

local animationStorage = game.ReplicatedStorage.GameAnimations

local idleAnimation = nil
local runAnimation = humanoid:LoadAnimation(animationStorage.Link.Young.NoToolsRun)
local jumpAnimation = nil

local isIdle = true
local isRunning = false

humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if humanoid.MoveDirection == Vector3.new(0,0,0) and isRunning and not isIdle then
	isIdle = true
	isRunning = false
	--idleAnimation:Play()
	runAnimation:Stop()
elseif humanoid.MoveDirection ~= Vector3.new(0,0,0) and isIdle and not isRunning then
	isIdle = false
	isRunning = true
	--idleAnimation:Stop()
	runAnimation:Play()
end
end)

Any help is appreciated, thank you!

Print something inside each if statement and see if it prints, that’ll help narrow down the problem

After a little digging, I noticed that whenever the player is moved with humanoid:MoveTo(), the MoveDirection doesn’t change, and acts as 0, 0, 0. Is there a way to get that not happening? or do I need a custom system?

Well, what you could do is in the code that calls MoveTo, just have that code also play the running animation when it calls Moveto. Then you could use the MoveToFinished event and play the idle animation when it fires.

I’ll defiantly look into doing that! The issue with this is that I have multiple animations that need to only be played for running, I’ll try this method though, thank you!

You cannot access MoveDirection on the server, you can only access it on the client, for some reason. You have to somehow read the MoveDirection from the client, through either a RemoteEvent or a RemoteFunction.

Read the article for more info:

2 Likes

Thanks for the help! I ended up finding a solution! (Not the most efficient, but it works.)

game["Run Service"].RenderStepped:Connect(function()
local oldPos = character.HumanoidRootPart.Position.X
wait(0.05)
local newPos = character.HumanoidRootPart.Position.X
if oldPos == newPos and isRunning and not isIdle then
	isIdle = true
	isRunning = false
	--idleAnimation:Play()
	runAnimation:Stop()
elseif oldPos ~= newPos and isIdle and not isRunning then
	isIdle = false
	isRunning = true
	--idleAnimation:Stop()
	runAnimation:Play()
end
end)