# onResourcePreStart (Server)

> Fired when a resource is starting, before its scripts run. Cancelling the event keeps the resource from starting.

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

## Syntax

```lua
addEventHandler("onResourcePreStart", root, function(resource resource) ... end)
```

## Handler parameters

| Name | Type | Description |
| --- | --- | --- |
| `resource` | `resource` | The resource that is starting. |

## Source

The element of the resource that is starting.

The resource's own scripts have not run yet, so only other resources get this event, with a handler on `root`.

## Example

```lua
addEventHandler("onResourcePreStart", root, function(resource)
    if getResourceName(resource) == "freeroam" and getResourceFromName("race") then
        cancelEvent()
    end
end)
```

## See also

- [onResourceStart (Server)](https://wiki.mymp.gg/en/onResourceStart.md): Fired when a resource has finished starting, after its scripts and maps have run.
- [startResource (Shared)](https://wiki.mymp.gg/en/startResource.md): Starts a resource right away, after starting the resources it includes with <include> in its meta.xml.
- [cancelEvent (Shared)](https://wiki.mymp.gg/en/cancelEvent.md): Marks the running event as cancelled. What cancelling prevents depends on the event.
