From the reference libraryFiveM

onNet-server

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

onNet-server


title: onNet - server

Use onNet function when you want to listen from server AND from client.
This declares an event which gets triggered with emit (from server) or emitNet (from client).

Signature

function onNet(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

onNet(
  "myResource:doMassiveStuff",
  (heavyArg: Array<string>) => {
    heavyArg = heavyArg.map(val => val + ".");
    // Note that source is accessible when the event is called from a client.
    // Read more on emit on the dedicated emit page
    emit("myResource:returnMassiveStuff", source, heavyArg);
  }
);
Back to documentation