Animation Not Adjusting Speed

  1. What do you want to achieve? I want my sword running animation to set Speed to 0 when it reaches the keyframe

  2. What is the issue? The issue is that it is not adjusting speed at all without error but it’s still printing at the end

  3. What solutions have you tried so far? I’ve looked for solutions but none have helped. I’ve tried other keyframes to freeze on too

game:GetService("ReplicatedStorage").Events.RunEquip.OnClientEvent:Connect(function(action)
    if action == "Running" then
        if Equipped == true then
            RunAnim.Priority = Enum.AnimationPriority.Movement
            RunAnim:Play()
        
            RunAnim.KeyframeReached:Connect(function(name)
                if name == "Hold2" then
                    RunAnim:AdjustSpeed(0)
                    print "adjsuted"
                end
            end)
        end
    end
end)
1 Like

You can just Pause the animation when it reaches the Keyframe.

RunAnim.KeyframeReached:Connect(function(name)
                if name == "Hold2" then
                    RunAnim:Pause()
                    print "paused"
                end
            end)

I did not know that was even a function lmao. I’ll try it in a second.

Yeah AnimationTrack:Pause() doesn’t even exist

https://developer.roblox.com/en-us/api-reference/class/AnimationTrack

That’s the correct way to pause an animation although this code will run into a memory leak due to the nested event connections.

Which nested connections? and also my problem was that the animation doesn’t freeze even when I adjust the speed to 0. I already tried it and for some reason it’s not working but not producing errors either

Edit: Im a little stupid, I know what you mean by nested connections now, but what is a better alternative?

Nested connections themselves are fine, you just need to remember to disconnect them so that future connections don’t stack.

1 Like

Here is one way to disconnect it

    if action == "Running" then
        if Equipped == true then
            RunAnim.Priority = Enum.AnimationPriority.Movement
            RunAnim:Play()
        
            local keyframeConnection --the variable that will hold the connection
            keyframeConnection = RunAnim.KeyframeReached:Connect(function(name)
                if name == "Hold2" then
                    RunAnim:AdjustSpeed(0)
                    print("adjsuted")
                    keyframeConnection = keyframeConnection and keyframeConnection:Disconnect() --checking if the connection exists then disconnects it
                end
            end)
        end
    end
1 Like

Ooh alright. Yeah I’ve been trying to be anti-memory leak so tysm for the suggestion.

But back on topic, can I get help on the animation like why it’s not adjusting speed?

If that keyframe is the last keyframe the animation might end instead of pausing, you could try this:

RunAnim:AdjustSpeed(0)
RunAnim.TimePosition = RunAnim.Length - 0.01
print("adjsuted")
keyframeConnection = keyframeConnection and keyframeConnection:Disconnect()
1 Like

Yep that worked. Thanks for the help!

1 Like