# import (Shared)

> Runs a resource's module in this script's Lua state, once per state, and gives back what it returned. The globals the module set become this script's.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Resources and modules
- **URL**: https://wiki.mymp.gg/en/import

## Syntax

```lua
any import(string|table module)
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `module` | `string\|table` | `"@resource/module"`, or `"@resource"` for its `main` module. A table of global names limits what is handed over to those names: `import { "a", "b" } "@resource/module"`. |

## Returns

What the module returned, or `true` if it returned nothing. With a table, a function that takes the module's name and does the import.

Every `*.lua` under a resource's `modules/` is a module, with nothing in `meta.xml`. Those in `modules/server/` are server-only and never sent, those in `modules/client/` client-only, and the rest shared. The name is the path under `modules/` without `.lua` and without a leading `server/` or `client/`; a side's own file wins over a shared one of the same name.

On the server, importing a resource that is not running starts it first. On the client, the resource must already be loaded on this client. A second `import` of the same module in the same state does not run it again; it only hands over the globals and the return value again.

## Example

```lua
local sql = import "@lp_database/sql"

import { "formatMoney" } "@utils"

outputDebugString(formatMoney(1500))
```

### Note

Problems raise errors, not `false`: a resource or module that does not exist, a module of the other side, one that does not compile, one imported again while it runs, or a name in the table the module does not define.

## See also

- [getResourceFromName (Shared)](https://wiki.mymp.gg/en/getResourceFromName.md): Finds a resource by name.
- [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.
- [call (Shared)](https://wiki.mymp.gg/en/call.md): Calls a function another resource exports in its meta.xml and returns what it returns.
