Source shows as nil on playerConnecting event

Hey everyone,

I am trying to parse the source number on the playerConnecting event however I’m receiving nil whenever I print it. Here’s my code:

AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)

print(source) --prints nil

end)

My server setup:
Node: v12.13.0
OS: Windows 11
Version: FXServer-master SERVER v1.0.0.4394 win32
OneSync: enabled
Max Clients: 32
txAdmin Version: 4.4.2
I’m connecting via localhost and specifically the button on the home screen that shows my PC.

Let me know if I am doing something wrong or this is a bug.

Hello,
Did you solve your problem ?

If not, is this code in a server script?

I have not solved the problem. It is indeed a server script.

It is strange ! Can you send all resource script ?

AddEventHandler('playerConnecting', function()
  local _source = source
  print(_source) 
end)

This is working for me.

2 Likes

I don’t see how this can work since source is nil and setting it to another variable shouldn’t work but this is FiveM I guess. Will try when at home.

@TGhost the resource is literally just a AddEventHandler with playerconnecting and nothing else. Again defined on fxmanifest as a server script.

1 Like

You have to make sure to store it in a local variable first, like @MasiBall did. Source is kinda weird, and will sometimes not work correctly if you don’t store it in a local var.

Also, note that the source provided by “playerConnecting” is TEMPORARY! It’s not 100% unique and it will be useless after the player successfully joins the server and is assigned a permanent sourceID.

I’m only looking for the source ID so I can get their identifiers using the GetPlayerIdentifiers() function. I don’t mind if they get another ID afterwards.

1 Like

Just got home and tested this. It works like a charm. Thanks mate!

1 Like

It’s not ‘kinda weird’ nor ‘sometimes’, it’s a global and if you use Wait the global will be gone and overwritten by something else since >global.

2 Likes