Best way to make a animation freeze at the end of the animation

Hello, I have an animation that i play when pressing Q, it does the animation and I want the animation to stop when its at the end of the animation and when the player lifts there finger off Q then the animation resets. What would be the best possible fix?

local UIS = game:GetService("UserInputService")
local animation = game.Workspace.Animations.LeanLeft
local humanoid = game.Players.LocalPlayer.Character.Humanoid

UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.Q then
        local animationTrack = humanoid:LoadAnimation(animation)
        wait()
        animationTrack:Play()
    end
end)
1 Like
local UIS = game:GetService("UserInputService")
local animation = game.Workspace.Animations.LeanLeft
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local animationTrack = humanoid:LoadAnimation(animation)

UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.Q then
        animationTrack:Play()
    end
end)


UIS.InputEnded:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.Q then
        animationTrack:Stop()
    end
end)

Wouldn’t something like this work ? :slight_smile:

PS : If you want to freeze the animation you can adjust the speed to 0 of the animation track

How would i set the speed to 0?

1 Like

So for example :

animationTrack:AdjustSpeed(0) --this will pause the animation
3 Likes

thanks, i got it working. I’ll post more info if i need more help

I have my script in Starterplayer scripts, and a folder in workspace called Animations with all of my animations. Is this layout practical?

CAN be… because either way in a Local Script or not exploiters can change the ID’s of said animation. IF the Script / Animation is within reach of said exploiter.

But if someone does change the ID it will not replicate

1 Like

Sorry. That’s what i was pointing at.
I’m not a great explainer sometimes.

But that’s what i was trying to say of sort.

also, is there a way to make the animation play without the character interfering with it when the player moves?

Yes. When creating the Animation you have a few options to select what type it’ll be.
Type meaning whether a specific animation can stop yours and play instead or interfering with the Standard animations to move.

The one you most likely want is Action or Movement.

Also side note: Don’t loop the animation within the Animations itself.
In the script when loading you can do:

Anim.Looped = true

2 Likes