Collapse Sidebar


This event fires whenever a looped AnimationTrack completes a loop, on the next update.

Currently it may also fire at the exact end of a non looped animation track but this behavior should not be relied upon.

Code Samples

Play AnimationTrack for a Number of Loops

The function in this code sample will play an AnimationTrack on a loop, for a specific number of loops, before stopping the animation.

In some cases the developer may want to stop a looped animation after a certain number of loops have completed, rather than after a certain amount of time. This is where the DidLoop event can be used.

local function playForNumberLoops(animationTrack, number)
	animationTrack.Looped = true
	local numberOfLoops = 0
	local connection = nil
	connection = animationTrack.DidLoop:Connect(function()
		numberOfLoops = numberOfLoops + 1
		print("loop: ", numberOfLoops)
		if numberOfLoops >= number then
			connection:Disconnect() -- it's important to disconnect connections when they are no longer needed