So I’m having this problem which is very annoying, since I want it to stop when jumping or falling and it doesn’t.
It’s a running animation, so it triggers when the speed is above the specified minimum. And that works.
What doesn’t work is that when you jump or fall, even after trying to stop it, it won’t, and there’s a bunch of checks that should prevent this from happening.
I’ve came here to get an answer of why this happens, as I can’t find the reason of why this is happening.
The code is inside a LocalScript.
Here’s the fragment that does this function:
task.spawn(function()
local mChar = player.Character
local mHum:Humanoid = mChar:WaitForChild('Humanoid')
local Load = mHum:LoadAnimation(script.Anim)
local jumping = false
local falling = false
local Speed = 0
mHum.Running:Connect(function(s)
Speed = s
end)
mHum.Jumping:Connect(function(a)
if a then
jumping = true
else
jumping = false
end
end)
mHum.FallingDown:Connect(function(a)
if a then
falling = true
else
falling = false
end
end)
while wait() do
local max = mHum.WalkSpeed
if (not jumping) and (not falling) then
if Speed > 2 then
Load:AdjustSpeed(1*(Speed/max))
Load:AdjustWeight(2*(Speed/(max)))
Load:Play(0.1)
while Speed > 2 and (not jumping) and (not falling) do
Load:AdjustSpeed(1*(Speed/max))
Load:AdjustWeight(2*(Speed/(max)))
wait()
if jumping or falling then
break
end
end
Load:Stop(0.1)
while jumping or falling do wait() end
else
Load:Stop(0.1)
end
else
Load:Stop(0.1)
end
end
end)