Fundamentals: your first resource · Lesson 3/6 · 9 min
Client vs Server: the key mental model
The client runs on the player's PC (untrusted); the server is the authority. They communicate through events.
This is THE concept that separates a secure script from a sieve. Client code runs on each player's PC: anyone can tamper with it. Server code runs on your machine: it's the only source of truth.
Golden rule: anything that grants money, items or an advantage is DECIDED and EXECUTED on the server. The client only asks; never trust what it sends.
Talking between client and server: events
-- CLIENT: asks the server to pay a salary
RegisterCommand('sueldo', function()
TriggerServerEvent('taxi:server:cobrarSueldo')
end)
-- SERVER: decides and executes (authority)
RegisterNetEvent('taxi:server:cobrarSueldo')
AddEventHandler('taxi:server:cobrarSueldo', function()
local src = source -- ID of the player who triggered the event
-- here you validate and grant the money on the server
print(('Player %s requested their salary'):format(src))
end)Client → Server
- TriggerServerEvent('name', ...): the client notifies the server.
- TriggerClientEvent('name', targetId, ...): the server notifies a client.
- RegisterNetEvent + AddEventHandler: register a network event to listen for it.
- source (server-side only): the ID of the player who triggered the event.
Recommended naming convention: resource:client:action and resource:server:action. That way you know at a glance where each event lives.
Challenge: code it yourself
Make a /hola command on the client that triggers an event to the server, and have the server print the player's ID to the console.
Write it yourself in your editor (VS Code) and test it on your server. You learn here by doing it, not by copying.
See hint
RegisterCommand in client.lua → TriggerServerEvent; RegisterNetEvent + AddEventHandler in server.lua using source.
Escribe aquí tu solución:
