PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

AnimationPlayed

The AnimationPlayed event fires when an AnimationTrack begins playing on the Humanoid.

A common use for this function is to connect the AnimationTrack/KeyframeReached event for the playing AnimationTrack, so additional effects can be added to the animation (for example Sound|Sounds and ParticleEmitter|ParticleEmitters).

This event can be used for any Humanoid regardless if it belongs to the local player’s client or not.

See also

  • For the AnimationController equivalent of this event, please see AnimationController/AnimationPlayed

Parameters

Name Type Default Description

The AnimationTrack that has begun playing


Code Samples


Pausing An Animation When a KeyFrame is Reached

The example below pauses any AnimationTrack playing on the humanoid when a keyframe named ‘PausePlayback’ is reached.

humanoid.AnimationPlayed:Connect(function(animationTrack)
	-- make sure the track exists
	if not animationTrack then
		return
	end
	local connection
	-- connect the KeyframeReached event
	connection = animationTrack.KeyframeReached:Connect(function(keyframeName)
		if keyframeName == "PausePlayback" then
			-- adjust speed to 0, pausing the animation
			animationTrack:AdjustSpeed(0)
		end
	end)
	-- disconnect the KeyframeReached event when the animation finishes
	animationTrack.Stopped:Wait()
	connection:Disconnect()
end)