Lua5.3: Main.lua:2: attempt to call a nil value (global 'TriggerEvent') stack traceback: Main.lua:2: in main chunk [C]: in?

Not sure what’s going on guys!! Hoping I can get a little insight on the issue…

ESX = nil
TriggerEvent(‘esx:getSharedObject’, function(obj) ESX = obj end)

RegisterNetEvent(‘np_selltonpc:dodeal’)
AddEventHandler(‘np_selltonpc:dodeal’, function()
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer ~= nil then
local weedprice = math.random(150, 500)
local weedamount = math.random(1, 5)

	local finalamount = weedprice * weedamount

	TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'success', text = 'You sold ' .. weedamount .. ' weed for $' .. finalamount, length = 4000 })
	xPlayer.removeInventoryItem('weed', weedamount)
	xPlayer.addAccountMoney('black_money', finalamount)
end

end)

Hi, that registers a client event, try this:

RegisterServerEvent('np_selltonpc:dodeal')
AddEventHandler('np_selltonpc:dodeal', function()
    local _source = source
	local xPlayer = ESX.GetPlayerFromId(source)
	if xPlayer ~= nil then
	    local weedprice = math.random(150, 500)
	    local weedamount = math.random(1, 5)
	
		local finalamount = weedprice * weedamount
	
		TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'success', text = 'You sold ' .. weedamount .. ' weed for ' .. finalamount, length = 4000 })
		xPlayer.removeInventoryItem('weed', weedamount)
		xPlayer.addAccountMoney('black_money', finalamount)
	end
end)

And use it in a client-sided file as:

TriggerServerEvent('np_selltonpc:dodeal')

thanks, will give it a try now

still throwing this error…

lua: main.lua:2: attempt to call a nil value (global ‘TriggerEvent’)
stack traceback:
main.lua:2: in main chunk
[C]: in ?