# setPedAnimation (Client)

> Makes a ped play an animation from a block, or stops the animation it is playing. The animation applies on this client only.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Client
- **Category**: Animations
- **URL**: https://wiki.mymp.gg/en/setPedAnimation

## Syntax

```lua
bool setPedAnimation(element ped [, string|false block = nil, string anim = nil, int time = -1, bool loop = true, bool updatePosition = true, bool interruptible = true, bool freezeLastFrame = true, int blendTime = 250, bool restoreTask = false])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `ped` | `element` | The ped or player. An element with peds below it in the tree applies to all of them. |
| `block` | `string\|false` | The animation block's name. `false` or left out together with `anim` stops the animation. *(default: `nil`)* |
| `anim` | `string` | The animation's name inside the block. Without it, the current animation stops. *(default: `nil`)* |
| `time` | `int` | How long the animation runs, in milliseconds. `-1` has no limit. *(default: `-1`)* |
| `loop` | `bool` | Repeat the animation. *(default: `true`)* |
| `updatePosition` | `bool` | Let the animation move the ped through the world. *(default: `true`)* |
| `interruptible` | `bool` | Let the game's reactions, such as being pushed, interrupt the animation. *(default: `true`)* |
| `freezeLastFrame` | `bool` | Hold the last frame instead of leaving the animation when it ends. *(default: `true`)* |
| `blendTime` | `int` | Blend time into the animation, in milliseconds. *(default: `250`)* |
| `restoreTask` | `bool` | If the ped was crouching, crouch again when the animation ends. *(default: `false`)* |

## Returns

`true` if the animation started or stopped on the element given, `false` if the block does not exist or the element is not a ped.

The animation is kept while the ped is streamed out and resumes at the right point when it comes back.

## Example

```lua
addCommandHandler("dance", function()
    setPedAnimation(localPlayer, "DANCING", "dance_loop")
end)

addCommandHandler("stopanim", function()
    setPedAnimation(localPlayer)
end)
```

## See also

- [getPedAnimation (Client)](https://wiki.mymp.gg/en/getPedAnimation.md): Tells which setPedAnimation animation a ped is playing on this client.
- [setPedAnimationSpeed (Client)](https://wiki.mymp.gg/en/setPedAnimationSpeed.md): Changes the speed of an animation the ped is playing.
- [setPedAnimationProgress (Client)](https://wiki.mymp.gg/en/setPedAnimationProgress.md): Jumps an animation the ped is playing to a point in it. Without anim, it stops the setPedAnimation animation.
