Creating a quest that requires the player to return to quest giver after doing task for quest to be completed.

Essentially I would like for the system to work like this:

Player interacts with quest giver to start quest.
Player must obtain ItemX for quest giver
Player obtains ItemX
Player returns to quest giver to complete quest.

Currently, this item quest ends as soon as the player picks up the item, and I would rather have it set up
so that the player can’t end the quest until he returns to the quest giver.
I’m still new to programming, and I apologize for how unorganized my code looks, but I assume having some relevant examples of the code I’m using will shed some light.

This is the bit that checks for quest triggers

    private void OnTriggerEnter2D(Collider2D other)
    {
        if(other.gameObject.tag == "Player" && !theQM.questCompleted[questNumber])
        {
                if(startQuest && !theQM.quests[questNumber].gameObject.activeSelf)
                {
                    theQM.quests[questNumber].gameObject.SetActive(true);
                    theQM.quests[questNumber].StartQuest();
                }

                if(endQuest && theQM.quests[questNumber].gameObject.activeSelf)
                {
                    theQM.quests[questNumber].EndQuest();
                }
        }
    }

You’ll notice it’s lacking any checks or references for any type of quest items.
Currently, I have a separate script for that, which looks like this…

    private void OnTriggerEnter2D(Collider2D other)
    {
        if(other.tag == "Player")
        {
            if(!theQM.questCompleted[questNumber] && theQM.quests[questNumber].gameObject.activeSelf)
            {
                theQM.itemCollected = itemName;
                gameObject.SetActive(false);
            }
        }
    }

Now, both of these quest scripts are working, but the problem is that in the first script I am able to set
where the quest will start, and where it will end, but with the quest item script, the quest will always end
at the moment I pick up the item. I’m sure there is a way I can combine my quest item check with my original quest trigger script, but I feel like I’m just beating my head against a wall right now.
I tried searching here and on google, but I wasn’t able to find anything helpful.
If there is anyone who can point me in the right direction I would be much appreciative, and I do apologize if there’s anything I’m missing. Cheers!

It feels like there should be some kind of quests manager in your game (use Singletons or scriptable object so you can easily reference it from other scripts). When the player accept the quest the quest giver register it in this global quest manager. Then, I suppose, you have some kind of quest resolver generator, a piece of logic to actually instantiate the staff in game world so the player can find them and complete the quest. This generator should be also separated thing (you better separate things rather than mix all inside one monolithic script) and it can be invoked from the Quest manager with parameters, now what are parameters, you can struct all your quests using scriptable objects as it allows you to easily manage them later. Finally when you player encounter quest resolving object (it might be NPC character or just an item laying on the ground or some chest, generated with your Quest generator) this quest resolver object call the Quest manager with result of quest (maybe you want it to fail for some reason ). Quest manager can have static events like “OnQuestUpdate”, and somewhere you have a UI script subscribed to this event to show popup hints (what to do next), in case you have to turn back to the quest giver your UI will say that (because you set this condition in the quest data ).
Another useful thing is to have UI Popups with updates delayed till you close some other UI (say opens chest UI or NPC interaction UI) , this can be solved with some kind of UI queue manager, or you may have enough screen estate to show all together.
As you can see, this may become really complex as you go, but you better reason about overall architecture before starting to code it. Try too separate concepts as much as you can. The more modularity you have the easier you can make changes later on while your game grows and new features are added.