Create a basic FiveM script from zero
Every FiveM resource starts with three things: a folder, a manifest, and a script. This lesson builds the simplest possible resource - one that prints to console, responds to a chat command, and detects a key press. By the end you understand the skeleton that every other lesson builds on.
Build it
Create the folder and manifest
resources/qu_first_script/
fxmanifest.lua
client.lua
fx_version 'cerulean'
game 'gta5'
client_script 'client.lua'
Restart the resource: ensure qu_first_script in server console or txAdmin Live Console.
Print to console on resource start
-- Runs once when the resource starts
CreateThread(function()
print('Hello from my first script!')
end)
Open F8 in-game. Restart the resource with ensure qu_first_script. You should see your message.
Add a chat command
-- Register a command players can type in chat
RegisterCommand('hello', function(source, args)
print('Player typed /hello')
print('Arguments: ' .. json.encode(args))
end, false)
In-game, open chat (T) and type /hello world. The args table contains everything after the command name.
Detect a key press
-- Check for key presses every frame
CreateThread(function()
while true do
if IsControlJustPressed(0, 38) then -- 38 = E key
print('E key pressed!')
end
Citizen.Wait(0)
end
end)
IsControlJustPressed returns true only on the frame the key was first pressed - it won't spam. Full control list: https://docs.fivem.net/docs/game-references/controls/
Keep reading the full lesson
Sign in to start, then unlock every step of this lesson and the full FiveM School with a membership.
- Common failures
The remainder of Create a basic FiveM script from zero is available to FiveM School members.