How would I freeze my animation after it completes?

Hi! My animation plays fine but resets to the first frame as soon as the animation finishes. How would make it freeze or stop on the last frame and stay that way?

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

This will freeze the animation by setting its speed to zero. Also AnimationTrack is the animation you want to freeze.

AnimationTrack:AdjustSpeed(0) --This will pause the animation

If you want to know when the animation has completely finished, the Stopped event is what you’re looking for.

3 Likes

okay cool! i am now struggling to have the speed go to 0 when the animation is over. i found that i can do wait but sometimes its off and freeze like .1 second before. with the stopped event it doesnt seem to work, here is what i have:

click.MouseClick:Connect(function()
	dance:Play()
	if dance.Stopped == true then
		dance:AdjustSpeed(0)
		click:Destroy()
	end

end)

Try removing the == true in the Stopped event.

If that doesn’t work, you could make a separate function with the Stopped event connected to it.

AnimationTrack.Stopped:Connect(function()
    -- Code here
end)

okay so i did the second option and it seems to work, however it freezes too early, before the character hits the ground and is still in the air. here is my code:

local animation = script:WaitForChild('Animation')
local humanoid = script.Parent:WaitForChild('Humanoid')
local click = script.Parent.ClickDetector
local dance = humanoid:LoadAnimation(animation)

click.MouseClick:Connect(function()
	dance:Play()
	dance.Stopped:Connect(function()
		dance:AdjustSpeed(0)
		click:Destroy()

	end)

end)

make sure to use :Once instead of :Connect if youre planning on detecting the animation stop only once, otherwise you could cause a memory leak