Unable to send LocalPlayer from Client to Server?

I have tried to do this for the last hour or so. Running the following from the client:

TriggerServerEvent("exampleEvent", LocalPlayer);

Raises the following exception:

[   6136063] Error invoking callback for event playerSpawned: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
[   6136125]   at System.Reflection.MonoProperty.GetValue (System.Object obj, System.Object[] index) [0x00027] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 
[   6136156]   at CitizenFX.Core.MsgPackSerializer.Serialize (System.Object obj, MsgPack.Packer packer) [0x0025f] in C:\gl\builds\edf06b9b\0\cfx\fivem\code\client\clrcore\MsgPackSerializer.cs:140 
[   6136203]   at CitizenFX.Core.MsgPackSerializer.Serialize (System.Object obj, MsgPack.Packer packer) [0x0015e] in C:\gl\builds\edf06b9b\0\cfx\fivem\code\client\clrcore\MsgPackSerializer.cs:108 
[   6136250]   at CitizenFX.Core.MsgPackSerializer.Serialize (System.Object obj) [0x00020] in C:\gl\builds\edf06b9b\0\cfx\fivem\code\client\clrcore\MsgPackSerializer.cs:55 
[   6136281]   at CitizenFX.Core.BaseScript.TriggerServerEvent (System.String eventName, System.Object[] args) [0x00000] in C:\gl\builds\edf06b9b\0\cfx\fivem\code\client\clrcore\BaseScript.cs:110 
[   6136328]   at Test.Client.ScriptClient.OnPlayerSpawn (System.Dynamic.ExpandoObject Spawned, CitizenFX.Core.Vector3 Where) [0x00021] in <d6d8049a64864ef2aeaf190f3935baff>:0 
[   6136360]   at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
[   6136391]   at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 
[   6136438]    --- End of inner exception stack trace ---
[   6136469]   at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 
[   6136500]   at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 
[   6136531]   at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 
[   6136578]   at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 
[   6136610]   at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 
[   6136641]   at CitizenFX.Core.EventHandlerEntry+<Invoke>d__5.MoveNext () [0x00064] in C:\gl\builds\edf06b9b\0\cfx\fivem\code\client\clrcore\EventHandlerDictionary.cs:85 

Is possible to send the LocalPlayer from the client to the server without random tricks?

Please note that LocalPlayer is not null, I can use properties like LocalPlayer.IsAiming and functions like LocalPlayer.SetSuperJumpThisFrame();

Why are you trying to send the whole LocalPlayer object to the server?

LocalPlayer is just a CitizenFX.Core.Player object, and I need it to identify the origin of “exampleEvent”.

I don’t know how it works on c# exactly, but normaly you can’t handle a player on server side, just the network id.

I’m not sure at 100%

What? No, you don’t. That’s what FromSource is for, and in the worst case, you send the player’s server ID, not some whole object.

2 Likes