# removeEventHandler (Shared)

> Takes a function off an element's event, where `addEventHandler` put it.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Events
- **URL**: https://wiki.mymp.gg/en/removeEventHandler

## Syntax

```lua
bool removeEventHandler(string eventName, element attachedTo, function handler)
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `eventName` | `string` | The event's name. |
| `attachedTo` | `element` | The same element given to `addEventHandler`. |
| `handler` | `function` | The same function given to `addEventHandler`. |

## Returns

`true` if it was removed, `false` if that function was not on that event of that element.

A handler removed while the event is already running is not called for the rest of that trigger.

## Example

```lua
local function onFirstSpawn()
    outputDebugString(getPlayerName(source) .. " spawned for the first time")
    removeEventHandler("onPlayerSpawn", source, onFirstSpawn)
end

addEventHandler("onPlayerJoin", root, function()
    addEventHandler("onPlayerSpawn", source, onFirstSpawn)
end)
```

## See also

- [addEventHandler (Shared)](https://wiki.mymp.gg/en/addEventHandler.md): Makes a function run whenever the event happens on the given element or, with propagate, on any of its descendants.
- [getEventHandlers (Shared)](https://wiki.mymp.gg/en/getEventHandlers.md): Lists the functions this resource put on an element's event with addEventHandler.
