Hi I am using esx_menu_default and i want to open a menu for a closesplayer/targetsrc but i have no idea. I need to open this menu because i need accept or decline menu for a billing. My code look like this

client side

local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()

        if closestPlayer ~= -1 and closestDistance < 3 then

            ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'set_vehicle_owner_sell_amount', {

                title = _U('invoice_amount')

            }, function(data2, menu2)

                local amount = tonumber(data2.value)

                if amount == nil then

                    ESX.ShowNotification(_U('invalid_amount'))

                else

                    menu2.close()

                    local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()

                    local targetSrc = GetPlayerServerId(closestPlayer)

                    if closestPlayer == -1 or closestDistance > 3.0 then

                        ESX.ShowNotification(_U('no_players'))

                    else

                        --TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(closestPlayer), 'society_cardealer', _U('car_dealer'), amount)

                        TriggerServerEvent('esx_vehicleshop:payforcar', amount, targetSrc)

                    end

                end

            end, function(data2, menu2)

                menu2.close()

            end)

        else

            ESX.ShowNotification(_U('no_players'))

        end

server side

RegisterNetEvent(‘esx_vehicleshop:payforcar’, function (amount, targetSrc)

local xPlayer = ESX.GetPlayerFromId(source)

print(amount)

ESX.UI.Menu.CloseAll()

ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'reseller',{

    title    = 'sssss',

    align    = 'center',

    elements = {

        {label = 'Akcpetuj', value = 'accept'},

        {label = 'Odrzuć', value = 'decline'},

}}, function(data, menu)

    if data.current.value == 'accept' then

          xPlayer.removeMoney(amount)

    elseif data.current.value == 'decline' then

        print('decline')

    end

end, function(data, menu)

    menu.close()

end)

end)

Hey :slightly_smiling_face:
The client part seemed good, the server part add some issues.

-- CLIENT -------------------------------------------------------------------------------------------------------------------

local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()

if closestPlayer ~= -1 and closestDistance < 3 then

            ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'set_vehicle_owner_sell_amount', 
			{

                title = _U('invoice_amount')

            }, 
			
			function(data2, menu2)

                local amount = tonumber(data2.value) --data2.current.value ? 

                if amount == nil then

                    ESX.ShowNotification(_U('invalid_amount'))

                else

                    menu2.close()

                    local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()

                    local targetSrc = GetPlayerServerId(closestPlayer)

                    if closestPlayer == -1 or closestDistance > 3.0 then

                        ESX.ShowNotification(_U('no_players'))

                    else

                        TriggerServerEvent('esx_vehicleshop:payforcar', amount, closestPlayer)

                    end

                end

            end, function(data2, menu2)

                menu2.close()

            end)

else
	ESX.ShowNotification(_U('no_players'))
end

--Event that will open the menu to accept/decline the bill
RegisterNetEvent('esx_vehicleshop:OpenBillRequest')
AddEventHandler('esx_vehicleshop:OpenBillRequest', function(amount,billingPlayer)

	table.insert(MenuOptions, {["label"] = "Accept Bill", ["value"] = true })
	table.insert(MenuOptions, {["label"] = "Decline Bill", ["value"] = false })
	
	ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'GarageBilling',
			{
				title    = "Bill from"..billingPlayer..": "..amount.."$",
				align    = 'top-left',
				elements = MenuOptions
			},
			
			function(data, menu)
			
				local choice = data.current.value
				
				--If the player accepts
				if (choice) then
					TriggerServerEvent('esx_vehicleshop:payementproceced', amount)
					 ESX.ShowNotification("You paied a "..amount.."$ bill")
				end
				
			end, 
			
			function(data, menu)
				 menu.close()
	end)
			
			

end)

---------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------


-- SERVER ------------------------------------------------------------------------------------------------------------------------

RegisterNetEvent('esx_vehicleshop:payforcar')
AddEventHandler('esx_vehicleshop:payforcar', function (amount, targetSrc)

	local billingPlayer = source
	local billedPlayer = targetSrc
	local amount = amount
	
	--Open the menu for the player who needs to pay the bill
	TriggerClientEvent('esx_vehicleshop:OpenBillRequest',targetSrc, amount, billingPlayer)


end)

RegisterNetEvent('esx_vehicleshop:payementproceced')
AddEventHandler('esx_vehicleshop:payementproceced',function (amount)

	local _source = source	
	local xPlayer = ESX.GetPlayerFromId(source)
	xPlayer.removeMoney(amount)
	
end)

---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------

Hey

Still it is not working. My friend (player next to me) is not receiving a menu where he can choose between this two options

Try to do some print testing, should help to see what’s going on.
Like printing ‘amount’, ‘billingPlayer’, ‘closestPlayer’ etc… at the beggening of each event and functions.

Then check if the datas you are printing make sense.
The communication goes :
Your client → Server → His client → Server

ok i will try and give you info and if i solve this problem i will post a solution here

Ok so my solution to this problem is

That is my client side after in some data.current.value

local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()

        if closestPlayer ~= -1 and closestDistance < 3 then

            ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'set_vehicle_owner_sell_amount',

            {

                title = _U('invoice_amount')

            },

            function(data2, menu2)

                local amount = tonumber(data2.value) --data2.current.value ?

                if amount == nil then

                    ESX.ShowNotification(_U('invalid_amount'))

                else

                    menu2.close()

                    local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()

                    local targetSrc = GetPlayerServerId(closestPlayer)

                    if closestPlayer == -1 or closestDistance > 3.0 then

                        ESX.ShowNotification(_U('no_players'))

                    else

                        TriggerServerEvent('esx_vehicleshop:payforcar', amount, targetSrc)

                    end

                end

            end, function(data2, menu2)

                menu2.close()

            end)

        else

            ESX.ShowNotification(_U('no_players'))

        end

That is my client side i mean other event for a second player

RegisterNetEvent(‘esx_vehicleshop:OpenBillRequest’)

AddEventHandler(‘esx_vehicleshop:OpenBillRequest’, function(amount,billingPlayer)

local elements = {

    {label = 'Accept', value = 'accept'},

    {label = 'Decline', value = 'decline'}

}



ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'GarageBilling',

        {

            title    = "Bill from"..billingPlayer..": "..amount.."$",

            align    = 'center',

            elements = elements

        },

        function(data, menu)

            if data.current.value == 'accept' then


                TriggerServerEvent('esx_vehicleshop:payementproceced', amount)

                ESX.ShowNotification("You paied a "..amount.."$ bill")


            elseif data.current.value == 'decline' then

                menu.close()

            end

            menu.close()

        end, function(data, menu)

    menu.close()

end)

end)


And server side

RegisterNetEvent(‘esx_vehicleshop:payforcar’)

AddEventHandler(‘esx_vehicleshop:payforcar’, function (amount, targetSrc)

local billingPlayer = source

local billedPlayer = targetSrc

local amount = amount



--Open the menu for the player who needs to pay the bill


TriggerClientEvent('esx_vehicleshop:OpenBillRequest',targetSrc, amount, billingPlayer)

end)

RegisterNetEvent(‘esx_vehicleshop:payementproceced’)

AddEventHandler(‘esx_vehicleshop:payementproceced’,function (amount)

local _source = source  

local xPlayer = ESX.GetPlayerFromId(_source)

xPlayer.removeMoney(amount)

end)

That is my i know that you need to work a bit with a noticifactions if player decline or accept the bill but for now you need to do this on your own. I might edit this later