TriggerEvent: how scripts talk to each other
A real FiveM server runs lots of resources at the same time. They do not share variables directly, so they need a way to talk. That is what events are. An event is just a named message. One script fires it, another script listens for it. This lesson starts with the simplest version: same-side events using TriggerEvent.
Build it
Make the resource folder
Inside your server's resources folder, create this folder:
resources/qu_trigger_event
Create the files
Create this exact file layout:
resources/qu_trigger_event/
fxmanifest.lua
client.lua
Write fxmanifest.lua
Open fxmanifest.lua and paste this:
fx_version 'cerulean'
game 'gta5'
client_script 'client.lua'
No lua54 'yes' line. As of June 2025 that directive is deprecated and you no longer need to enable it: Lua 5.3 has been deprecated and every Lua script now runs on Lua 5.4 automatically, so you leave it out.
Write the lesson code
Open client.lua and paste this. Two handlers listen for the same event name, and one command fires that event:
AddEventHandler('qu_trigger_event:shout', function(message)
print('[qu_trigger_event] handler one ' .. message)
end)
AddEventHandler('qu_trigger_event:shout', function(message)
print('[qu_trigger_event] handler two ' .. message)
end)
RegisterCommand('shout', function(_, args)
TriggerEvent('qu_trigger_event:shout', table.concat(args, ' '))
end, false)
Start and test it
Open server.cfg and add this line:
ensure qu_trigger_event
Save, then run:
restart qu_trigger_event
This is a client_script, so the command runs from inside the game. Run /shout hello in chat, or type shout hello without a slash in F8.
Chat: /shout hello
F8: shout hello
Keep reading the full lesson
Sign in to start, then unlock every step of this lesson and the full FiveM School with a membership.
- How it works
- If something went wrong
- What you can do now
- Try it yourself
The remainder of TriggerEvent: same-side is available to FiveM School members.