How to Write and Use Exports in FiveM
How FiveM exports let one resource offer a function to others, how to declare and call them, and when to pick exports over events.
Short answer
An export lets one resource offer a function to other resources. The provider resource registers the function with exports('Name', fn). A consumer resource calls it through the exports table, for example exports['my-provider']:Name(...). The call stays inside the same Lua environment, client or server. Crossing the client and server boundary needs events instead.
What an export is
An export is a named function that belongs to a resource. Other resources can reach it without copying its code. The provider owns the function, and the consumer only needs the resource name and the export name. This is how many FiveM frameworks let other scripts open menus, check permissions, or read shared data.
Provider side
The provider registers the function with the global exports object. The name is what consumers will type, so pick something clear and stable.
-- my-provider/server.lua (placeholder example)
exports('SayHello', function(name)
return ('Hello, %s!'):format(name)
end)
The manifest must list the script that holds this code. A minimal fxmanifest.lua looks like this:
-- my-provider/fxmanifest.lua (placeholder example)
fx_version 'cerulean'
game 'gta5'
server_script 'server.lua'
The Lua runtime page also documents an export entry for client code and a server_export entry for server code in the manifest. Functions need to be global to be exported this way. Exports only become available after the first scheduler tick, so consumers should not call them in the same line that starts the resource.
Consumer side
The consumer calls the function through the exports table, using the provider's resource name and the export name. The Lua docs show the dot form for plain names:
-- my-consumer/server.lua (placeholder example)
local message = exports.myresource:SayHello('world')
print(message)
Resource names with hyphens cannot be used with the dot form, so use the bracket form instead: exports['my-provider']:SayHello('world'). In JavaScript, the same idea appears as exports.resourceName.exportName or exports['resourceName']['exportName'].
The call is local when both resources run on the same side. A server script calling a server export never touches the network. A client script cannot call a server export directly, so it must ask the server through an event.
Exports vs events
Use an export when another resource needs a function and wants a return value right away. Use an event when something happens and other scripts should react, or when the code must cross between client and server. Exports are direct calls. Events are messages that any listener can pick up. For the event side, see the FiveM events guide on this site.
Common mistakes
- Resource not started. If the provider is not running, its exports do not exist. Check that it is started before the consumer, usually in
server.cfg. - Wrong name. The resource name and the export name must match exactly, including case and hyphens.
- Wrong side. A client export is not visible to server code, and the reverse is also true. Move the call or use an event to cross the boundary.
- Calling too early. Exports only become available after the first scheduler tick, so avoid calling them from the same line that starts the resource.
FAQ
Can a client script call a server export?
No. Exports live on the side where they are defined. A client script that needs server data should send a request with an event, and the server should reply with another event.
Do I need the manifest entry to export a function?
The Lua runtime docs show exports('Name', fn) as the way to define an export. The manifest export and server_export entries are an alternative that the docs describe, with the note that functions must be global.
Why is my export missing right after the server starts?
Exports only become available after the first scheduler tick. Start the provider before the consumer, and avoid calling the export in the same moment the resource loads.
Sources
- Scripting in Lua, Cfx Documentation
- Exports (JavaScript), Cfx Documentation
- Resource Manifest, Cfx Documentation
Last checked: 30 November 2026
Note: The examples use placeholder names such as my-provider and myresource. Check the Cfx documentation for your server's current version before shipping code.
FiveM.tools was founded with sponsorship from Nyru.