
Tutorial: FiveM scripting in LUA
You want to write new scripts/programs for your FiveM server (or others)?
Every new beginning can be a challenge, but it’s definitely worth it to learn how to write code for FiveM. FiveM scripting isn’t that hard.
Good to know: FiveM uses LUA code for both client and server. For UI, it is good to use HTML, JS and CSS.
Setting up a server on FiveM
The easiest way to set up a FiveM server is to download a server template from ESX-Scripts.
- Create a new directory (for example
D:\FXServer\server
), this will be your server folder - Download the last server version of FiveM: artifacts server.
- Extract the files
- Download and extract cfx-server-data to a folder, for example to
D:\FXServer\server-data
. - Create a server.cfg file inside the directory:
server-data
(this is an example: example server.cfg). - Generate a new FiveM key from the keymaster: https://keymaster.fivem.net.
- Adjust the key inside the server.cfg:
sv_licenseKey "licensekey"
. - Start the server! Done.
Write own scripts
If you want to write own scripts, the best method is to look through already existing scripts. This is the best way to learn new ways of scripting and programming for FiveM servers.
However, here is an exciting video tutorial from YouTuber “Jeva” showing on how to create your first resource:
Resources
Resources are a collection of files that can be started, stopped, and restarted individually. A script is saved in a “resource”. For example: There is a resource for your cardealer, a resource for a weapon script, etc.
If you’re working on your own FiveM script, you’ve probably created a resource / [local] directory – this is ignored by Git when it updates the server data master. There we create a folder resources / [local] / GameMode, since we are creating a game type with the Mapmanager system. That means that we now need to have a folder like this, assuming a Windows development system: C: \ your \ path \ to \ cfx-server data \ resources \ [local] \ gamemode.
A manifest must be recognized by FiveM for a resource folder. Since this is a game type, some additional information is required to inform Mapmanager that it is a game type. Create a file in your GameMode folder called fxmanifest.lua (this is always Lua, even if you later write scripts in C # / JS).
txAdmin
txAdmin is a full featured web panel to Manage & Monitor your FiveM/RedM Server remotely, in use by over 10000 servers worldwide at any given time. Any FiveM server has txAdmin pre-installed!
Need help with txAdmin? Check out their github page.
Frequently asked questions
Well, all new things are hard. But don’t get frustrated too fast. Just keep on going. You might fail at first but it’s definitely worth it.
We recommend using the ESX framework to begin with. It is easy to understand and has the most downloadable addons (DLC) for it.
The best scripts are offered here on ESX-Scripts.
You can also check out the official FiveM forum for new development tips and resources.
Find the reason behind it! Check out your server console and download the error log via txAdmin.