Set up VS Code, your code editor
Right now you have FiveM installed and you have launched it. The next thing every developer needs is a place to actually write code. That place is called a code editor, and the one the whole FiveM world uses is free. In this lesson you install it and teach it to understand Lua, the language FiveM scripts are written in. By the end, your editor will finish your code for you and flag your typos before you ever run them.
Watch
What VS Code is
A code editor is a program for writing code, the same way a word processor is a program for writing essays. You could technically write code in Notepad, the basic text box that comes with Windows, but that is like writing an essay on a napkin. It works, barely, and you will regret it.
VS Code (short for Visual Studio Code) is a free code editor made by Microsoft. It is the standard tool FiveM developers use, which matters more than it sounds. When you hit a problem and search for help, almost every tutorial, every screenshot, and every Discord answer assumes you are in VS Code. Using the same tool as everyone else means their instructions just work.
The reason VS Code is worth installing instead of using Notepad is that it can be taught new skills through small add-on programs. That is the whole idea behind the next few terms.
Vocabulary
- Editor
- A program for writing and changing code. VS Code is an editor. Notepad is a much weaker one.
- Extension
- A small add-on you install into VS Code to give it a new skill, like understanding a specific programming language.
- Language server
- The brain behind an extension. It reads your code as you type and understands the rules of the language, so it can catch mistakes and make suggestions.
- Autocomplete
- When the editor finishes a word for you. You type the first few letters and it offers the full thing in a popup, so you stop guessing and stop misspelling.
- Syntax highlighting
- Coloring different parts of your code so they are easy to tell apart. Text is one color, commands another, numbers another. Your eyes learn to read it fast.
Why an editor that understands Lua matters
Lua is the programming language FiveM scripts are written in. A plain text editor like Notepad treats your Lua file as nothing but letters. It has no idea what the words mean, so it cannot help you when you make a mistake. And you will make mistakes. Every coder does, all day long.
An editor that understands Lua does three things a plain one never can:
- It catches typos the instant you make them. Misspell a word or forget a closing piece of punctuation, and a red underline appears right under the problem. You fix it in two seconds instead of restarting your whole server to discover the error later.
- It highlights your code in colors so the structure is obvious at a glance. A long file stops looking like a wall of text.
- It suggests FiveM functions as you type, so you are not memorizing thousands of exact names. You type the first few letters and pick the right one from a list.
Think of the difference like the difference between a plain notebook and a spell-checked document. The notebook never warns you when you write "teh" instead of "the." The document underlines it before you even finish the sentence. An editor that understands Lua is the spell-checker, but for code.
How it works
VS Code, fresh out of the box, does not know what Lua is. You teach it with two extensions. Each one plugs a new piece of knowledge into the editor.
The first extension teaches VS Code the rules of the Lua language itself: what counts as a typo, how the pieces of code fit together, what to autocomplete. This is the language server.
The second extension teaches VS Code about FiveM specifically. FiveM gives you thousands of ready-made functions called natives (functions the platform hands you for free, like one that gets a player's position). The second extension feeds all of their names into the editor so they autocomplete too. Without it, the editor would understand plain Lua but treat every FiveM function as an unknown word.
Set it up
Download and install VS Code
Go to the official site, code.visualstudio.com, and click the big download button for Windows. Run the file it downloads and accept all the default options. When you reach the screen with checkboxes, tick the ones that say "Open with Code," which let you right-click any folder and open it in the editor later.
Open the Extensions panel
Look at the narrow bar of icons down the left edge of VS Code. Click the icon that looks like four small squares with one square breaking away. That opens the Extensions panel, with a search box at the top. You can also press Ctrl+Shift+X to open it.
Install the Lua language server
In the Extensions search box, type Lua. You will see many results, so pick carefully. Install the one named simply Lua, published by LuaLS (you may also see it listed under the older name "sumneko"). It has millions of installs, far more than the others. Click the blue Install button on it.
Avoid the lookalikes that only color your code without checking it. The one you want is the language server, the brain that catches mistakes.
Add the FiveM native autocomplete
Still in the Extensions search box, type Cfx Lua. Install cfxlua-vscode, published by overextended. This is the extension that teaches the editor every FiveM native, so functions like RegisterCommand appear in the autocomplete popup.
The exact setup options for this extension can change over time, so its marketplace page is the place to check if you ever want the advanced settings. For now, installing it is all you need.
Open a folder and confirm autocomplete
Choose File, then Open Folder, and pick any folder on your PC (an empty one is fine for this test). Opening a folder, not a single file, is what lets the editor work properly.
Now create a new file. Click the new-file icon at the top of the file list on the left, name it test.lua (the .lua ending is what tells the editor this is Lua code), and start typing:
RegA small popup should appear suggesting RegisterCommand and other names that start with those letters. That popup is the proof everything is wired up correctly.
Common beginner mistakes
| Symptom | Fix |
|---|---|
No autocomplete popup appears at all | The extension is not installed, or VS Code has not fully loaded it. Open the Extensions panel and confirm both Lua (by LuaLS) and cfxlua-vscode (by overextended) show an Uninstall button. Then reload: press Ctrl+Shift+P, type Reload Window, and press Enter. |
You are still editing files in Notepad | Notepad cannot catch typos or autocomplete, so you lose every benefit you just set up. Always open your code in VS Code instead, where errors light up red as you type. |
Strange symbols appear in your file, like accented letters where you typed plain ones | This is a file encoding problem, where the file was saved in the wrong character format. In VS Code, look at the bottom-right status bar, click the encoding label, choose Save with Encoding, and pick UTF-8. UTF-8 is the format FiveM expects. |
VS Code suggests Lua words but no FiveM functions like RegisterCommand | The Lua language server is working but the FiveM extension is not. Confirm overextended.cfxlua-vscode is installed and reload the window. |
What does the Lua language server give you that a plain text editor does not?
A plain text editor like Notepad treats your file as meaningless letters. The Lua language server actually understands the rules of Lua, so it does three things Notepad cannot: it underlines your typos in red as you type, it colors the different parts of your code so the structure is readable, and it autocompletes function names so you stop guessing and stop misspelling. In short, it turns your editor into something that reads code the way you do, and warns you before mistakes cost you a server restart.
Try it yourself
What you can do now
- Explain what a code editor is and why VS Code beats Notepad for writing code.
- Install VS Code from code.visualstudio.com with the Open with Code option.
- Add the Lua language server (Lua by LuaLS) so the editor understands the language and catches typos.
- Add the FiveM native autocomplete (cfxlua-vscode by overextended) so FiveM functions autocomplete.
- Prove the setup works by typing Reg and seeing RegisterCommand suggested.
You now have the exact editor working FiveM developers use, taught to understand both Lua and FiveM. The last thing you need before writing real code is a place to put it and run it. Next up: "Your test server and the resources folder," where you set up a server you can break, fix, and learn on safely.