Hey DevForums, I’m working on a physics lab just to get better at scripting. I was working on a custom walking animation and all goes well. But the animation won’t stop playing even when I stop moving. One thing I’ve tried is checking the magnitude of the player HumanoidRootPart velocity (that way I made it so if the walk speed of the character is 0, it stops the anim. of course though, it doesn’t work).
Heres the code:
Character.Humanoid.Running:Connect(function(speed)
if speed <= 20 and speed > 0 then
Character.Humanoid:LoadAnimation(script:WaitForChild("Walking")):Play(0.2)
elseif speed == 0 or Character.HumanoidRootPart.Velocity.Magnitude == 0 then
Character.Humanoid:LoadAnimation(script:WaitForChild("Walking")):Stop(0.2)
end
end)
In my animation script or the default roblox anim script? If your saying the default, I would’ve done that, but the reason I went to the forums is because I wanted the animations to transition smoothly.
Your solution is simple! Create a reference to the loaded animation outside of the function. Your problem: in the code, you’re loading the animation each time. It only needs to be loaded once as shown:
local Animation = Character.Humanoid:LoadAnimation(script:WaitForChild("Walking"))
Character.Humanoid.Running:Connect(function(speed)
if speed <= 20 and speed > 0 then
Animation:Play(0.2)
elseif speed == 0 or Character.HumanoidRootPart.Velocity.Magnitude == 0 then
Animation:Stop(0.2)
end
end)
No, thats not the problem… you see for ex: the group owns the game, and if you own the animation then it wont play… so if the group owns the game make sure the group owns the animations too!!