From the reference libraryFiveM

on-client

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

on-client


title: On - client

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

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

// No arg
on("foo:imReady", () => {
    console.log("I'm ready to go!");
});

// With arg
on("foo:printMyDelivery", (delivery: string) => {
    console.log(`delivery received: ${delivery}`);
});

// Direct function call
on("foo:spawnMyCar", spawnCar);
Back to documentation