I want my idle animation to play when im not moving and I want my walking animation to play when my speed is 16 and my running animation to play when my speed is 29. It wont transition from the idle to walking/ walking to running unless I jump. Can anyone help me?
This is because your script is checking if the player’s speed is exactly equal to a value. The speed value is usually made up of decimals as a result of 64 bit limitations and inexact velocity. Try
humanoid.Running:Connect(function(speed)
if speed >= 16 then
if speed >= 29 then
IdleTrack:Stop()
WalkTrack:Stop()
RunTrack:Play()
else
RunTrack:Stop()
IdleTrack:Stop()
WalkTrack:Play()
end
else -- can put elseif speed == 0 then here, but not necessary.
RunTrack:Stop()
WalkTrack:Stop()
IdleTrack:Play()
end
end)
humanoid.Running:Connect(function(speed)
if speed >= 1 then
if speed >= 29 then
IdleTrack:Stop()
WalkTrack:Stop()
RunTrack:Play()
else
RunTrack:Stop()
IdleTrack:Stop()
WalkTrack:Play()
end
else -- can put elseif speed == 0 then here, but not necessary.
RunTrack:Stop()
WalkTrack:Stop()
IdleTrack:Play()
end
end)
this is because when running, your speed never actually reaches the value of the humanoid.WalkSpeed. If WalkSpeed is set to 29, the value will likely be around 28.97. Because of this, you have two options
humanoid.Running:Connect(function(speed)
if speed >= 1 then
if speed >= 28 then -- replace the value with the speed you want subtraced by 1
IdleTrack:Stop()
WalkTrack:Stop()
RunTrack:Play()
else
RunTrack:Stop()
IdleTrack:Stop()
WalkTrack:Play()
end
else
RunTrack:Stop()
WalkTrack:Stop()
IdleTrack:Play()
end
end)
-- or
humanoid.Running:Connect(function(speed)
if math.ceil(speed) >= 1 then
if math.ceil(speed) >= 28 then -- or use math.ceil
IdleTrack:Stop()
WalkTrack:Stop()
RunTrack:Play()
else
RunTrack:Stop()
IdleTrack:Stop()
WalkTrack:Play()
end
else
RunTrack:Stop()
WalkTrack:Stop()
IdleTrack:Play()
end
end)