AddEventHandler

Use this to listen for events, see the events page for more info.

Syntax

AddEventHandler(string eventName, function callback)

Required arguments

  • eventName: The name of the event you want to listen to.
  • callback: The function to run when the event is called.

Examples

– SERVER

Don’t forget to RegisterNetEvent!

AddEventHandler('eventName', function(text)
  print(('I just received %s from %i'):format(text, source)) -- I just received Hello world! from (player id)
  -- source is a global variable (Player's id)
end)

– CLIENT

TriggerServerEvent('eventName', 'Hello world!')