The Problem:
I am trying to make custom animations for my game but the animation script it is some time playing when it isn’t meant to and also some time not play when it is meant to be playing.
I Have Tried:
changing the function(speed) to function(speed) and with that setting the while speed do to while isActive do but with that the code didn’t work.
in Starter Character Scripts
local teddyWalkAnim = script.TeddyWalk --the walk animation
local humanoid = script.Parent.Humanoid
local animTrack --for doing extra code on top
humanoid.Running:Connect(function(speed)
animTrack = humanoid:LoadAnimation(teddyWalkAnim)
animTrack:Play()
while speed > 0 do
wait(0.01)
end
animTrack:Stop()
end)
I am not shore what the problem is and the model has a animator.
For a walk animation, it is not ideal to use humanoid.Running to decide whether or not to play the animation. If you were hit by an object or the player is sliding along a conveyor belt, the Running connection will play the walk animation and this is not desired.
I would recommend using Humanoid.MoveDirection to achieve a proper walk animation. The walk animation will only play IF the humanoid is detecting that the player itself is trying to walk.
local teddyWalkAnim = script.TeddyWalk --the walk animation
local humanoid = script.Parent.Humanoid
local animTrack --for doing extra code on top
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
animTrack = humanoid:LoadAnimation(teddyWalkAnim)
if humanoid.MoveDirection.Magnitude > 0 then -- if the humanoid is trying to move,
animTrack:Play()
elseif humanoid.MoveDirection.Magnitude <= 0 then -- if the humanoid is not moving/stopped moving
animTrack:Stop()
end
end)
As to the script that you are using, the speed variable will never change. Therefore, the while loop will pause the function if you are not moving, and it will immediately stop the animation once you start moving at a speed > 0. Hope this helps! Let me know if my script works if you decide to use it!
Also, make sure that your actual animation track has looping enabled and its animation priority is higher than idle.