How to pass player from client to server while triggering an event

Recommended Posts

I'm trying to pass player object to server while triggering an event and some people told me that is not needed because player is always a first parameter of event callback function

My structure looks like that:

Client:"onPlayerRequestRegister",(username, password, email)=>{
  // hud.destroy();
  //mp.gui.cursor.visible = false;
  const localPlayer = mp.players.local;
  if(!username) return hud.execute(`printError("Please enter your username");`);
  if(!email) return hud.execute(`printError("Please enter your email");`);
  if(!password) return hud.execute(`printError("Please enter your password");`);
  if(username && password && email){
    //trigger on reggister
    const user = {"player": localPlayer, "username": username, "password": password,"email":email} ;"onPlayerRequestRegister", JSON.stringify(user));


Server:"onPlayerRequestRegister", (args)=>{

and console.log("data",args) returns data { customData : {} } which is empty object,

So if somebody can write exact structure for event triggering that would be helpful.

Share this post

Link to post
Share on other sites



Server:"onPlayerRequestRegister", (player, args) => {
  console.log(`${} call onPlayerRequestRegister data : ${args}`);

if you call the event from the client side, the first argument on the server will always be the player who triggered the event

Edited by kemperrr

Share this post

Link to post
Share on other sites

first argument of server event always is player object"onPlayerRequestRegister", (player, args)=>{


Share this post

Link to post
Share on other sites

Try this

mp.trigger("callEvent", "onPlayerRequestRegister", JSON.stringify(user) );

I hope this helps


Edit more this"onPlayerRequestRegister", (player, args)=>{


Edited by John_Reaper

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.