# onElementModelChange (Server)

> Fired after `setElementModel` changes an element's model. Cancelling the event puts the previous model back, and `setElementModel` returns `false`.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Event
- **Side**: Server
- **Category**: Elements
- **Cancellable**: `cancelEvent`
- **URL**: https://wiki.mymp.gg/en/onElementModelChange

## Syntax

```lua
addEventHandler("onElementModelChange", root, function(string oldModel, string newModel) ... end)
```

## Handler parameters

| Name | Type | Description |
| --- | --- | --- |
| `oldModel` | `string` | The previous model's name. |
| `newModel` | `string` | The new model's name. |

## Source

The element whose model changed.

## Example

```lua
local allowed = { male01 = true, wmybar = true, bfori = true }

addEventHandler("onElementModelChange", root, function(oldModel, newModel)
    if getElementType(source) == "player" and not allowed[newModel] then
        cancelEvent()
    end
end)
```

## See also

- [setElementModel (Server)](https://wiki.mymp.gg/en/setElementModel.md): Changes the model of a ped or player, and of its children.
- [getElementModel (Shared)](https://wiki.mymp.gg/en/getElementModel.md): Reads the name of an element's model.
