From the reference libraryFiveM

on-server

fivem-docs/docs/scripting-reference/runtimes/javascript/functions/on-server.md

on-server


title: On - server

Use on function when you want to listen from server only.
This declares an event which gets triggered with emit from the server.

Signature

function on(eventName: string, fn: Function) => void

Signature > Required arguments

  • eventName: The event name you want to expose.
  • fn: The function to execute when the event get triggered.

Examples

on(
  "foo:kickBar",
                   // We can add callback
  (barId: string, cb: Function => {
    DropPlayer(barId, "Foo doesn't want you anymore!");
    cb("Job is done!");
  }
);

title: On - server

Use on function when you want to listen from server only.
This declares an event which gets triggered with emit from the server.

Back to documentation