[Help] Transferring Items from one player to another (cmd - not drop)

Hi all I am trying to make a function for my Addon DGRP_McDonaldsJob, but I have yet to figure out how to successfully transfer multiple items from one player to another.

Client Side Code:
RegisterCommand("giveorder", function(source, args)
    Citizen.CreateThread(function()
        if onDuty and currentJob == 'cook' and Config.EnableAdvancedMode == true then
            local receiver = tonumber(args[1])
            if invBurger > 0 and invDrink > 0 and invFries > 0 then
                if holdingBurgerNum > 0 and holdingDrinkNum > 0 and holdingSideNum > 0 then
                    if receiver then
                        if morningOrder == true then
                            dPrint("Gave Order to Player ID: "..receiver)
                            TriggerServerEvent('dgrp_mcdonalds:giveOrder', source, receiver, Config.Items.Burgers.Morning[holdingBurgerNum].id, Config.Items.Drinks.Morning[holdingDrinkNum].id, Config.Items.Sides.Morning[holdingSideNum].id)
                        else
                            dPrint("Gave Order to Player ID: "..receiver)
                            TriggerServerEvent('dgrp_mcdonalds:giveOrder', source, receiver, Config.Items.Burgers.Day[holdingBurgerNum].id, Config.Items.Drinks.Day[holdingDrinkNum].id, Config.Items.Sides.Day[holdingSideNum].id)
                        end  
                    else
                        dPrint("Couldnt Find player by ID")
                    end
                else
                    dPrint("Could not Identify the Items you Gathered!")
                end
            else
                dPrint("You do not have a Burger, Drink and Side to give to Cashier")
            end
        else
            dPrint("You are not a cook")
        end
    end)
end)
Server Side Code:
RegisterServerEvent('dgrp_mcdonalds:giveOrder')
	AddEventHandler('dgrp_mcdonalds:giveOrder', function(source, args, item1, item2, item3, item4)
	local xPlayer = ESX.GetPlayerFromId(source)	
	local receiver = ESX.GetPlayerFromId(args)

	if xPlayer ~= nil then
		xPlayer.removeInventoryItem(item1, 1)
		xPlayer.removeInventoryItem(item2, 1)
		xPlayer.removeInventoryItem(item3, 1)
		xPlayer.removeInventoryItem(item4, 1)
	else
		print("xPlayer is Nil unable to transfer Items.")
	end
	
	if receiver ~= nil then
		receiver.addInventoryItem(item1, 1)
		receiver.addInventoryItem(item2, 1)
		receiver.addInventoryItem(item3, 1)
		receiver.addInventoryItem(item4, 1)
	else
                print("Receiver is Nil unable to transfer Items.")
	end

end)

Error Details:
Screenshot_9

Extra Details:

I have only tried Transferring to myself which states that it sent successfully (client side)


but then I receive the error message server side, so it may be because I am trying to transfer to myself, but have no one to be able to test it, all my IRL friends are console freaks and hate everything about PC’s so no luck there and have never found a stable enough server to bother investing my time in so have no FiveM friends either… well thats untrue… the FiveM friends I have are only friends because they want admin on my server. So long story short, I have 0 people to test this with, could this be causing the error? or is there something wrong in my coding?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.