Attempt to call a nil value field getplayerfromid

Hey guys, trying to do when player creates character he gets phone in his inventory, but getting error.

RegisterNUICallback('register', function(data, cb)
	local reason = ""
	myIdentity = data
	for theData, value in pairs(myIdentity) do
		if theData == "firstname" or theData == "lastname" then
			reason = verifyName(value)
			
			if reason ~= "" then
				break
			end
		elseif theData == "dateofbirth" then
			if value == "invalid" then
				reason = "Netinkama gimimo data"
				break
			end
		elseif theData == "height" then
			local height = tonumber(value)
			if height then
				if height > 200 or height < 140 then
					reason = "Netinkamas ūgis"
					break
				end
			else
				reason = "Netinkamas ūgis"
				break
			end
		end
	end
	
	if reason == "" then
		TriggerServerEvent('esx_identity:setIdentity', data, myIdentifiers)
		EnableGui(false)
		Citizen.Wait(500)
		TriggerEvent('esx_skin:openSaveableMenu', myIdentifiers.id)
		local _source = source
	    local xPlayer = ESX.GetPlayerFromId(_source)
		xPlayer.addInventoryItem('phone', 1)
	else
		ESX.ShowNotification(reason)
	end
end)

Make sure the script is ESX based.

Try adding ESX = nil
At the start of the script

Already added. Its esx_identity script

Essentialmode has a native which you can use (First time log in listener) so look into that.
make a listener to es_firstJoin or whatever it’s called and add a phone to the person’s inventory and you’re done.
Also, why don’t you just give people money to start with and let them go to a shop and buy it themselves? would be much easier. good luck