[SOLVED] You cannot add or remove an unsaved Parse Object from a relation

I am trying to assign current user to a role using cloud functions but i keep getting this error
Error: You cannot add or remove an unsaved Parse Object from a relation

please does anyone has any idea about why i am getting this error.
here is the code

Moralis.Cloud.define('addUserToCollectorRole',async(request)=>{
  const roleInDB = new Moralis.Query(Moralis.Role);
  roleInDB.equalTo("name", "Collector");
  const result = await roleInDB.first({ useMasterKey: true }); 
 
  await result.getUsers().add(request.user.attributes);
 result.save();
  return request;
})

Since you’re trying to assign the current user to a role, you should pass the user object, not the user attribute object. Rather you should have

await result.getUsers().add(request.user);

You should also update the role saving in such way

  result.save(null, { useMasterKey: true });

instead of

Thank you. this fixed my problem