Pickup script making objects go through walls

I don’t want my object that I pick up to go through walls and I just want it to hit the wall and not move, but I don’t know how to add it in.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;


public class pickup : MonoBehaviour
{
    GameObject grabbedObject;
    float grabbedObjectSize;
    public GameObject gun1;
    public GameObject gun2;
    public GameObject gun3;
    [SerializeField] private string selectableTag = "pickupable";
    public bool hitpickupable;
    public OnCollision oc;



    // Use this for initialization
    void Start()
    {
        grabbedObject.GetComponent<Rigidbody>();
        grabbedObject.GetComponent<Collider>();
    }

    GameObject GetMouseHoverObject(float range)
    {
        //Check for Collider with Raycast
        Vector3 position = gameObject.transform.position;
        RaycastHit raycastHit;
        Vector3 target = position + Camera.main.transform.forward * range;
        if (Physics.Linecast(position, target, out raycastHit))
            return raycastHit.collider.gameObject;
        return null;
    }

    void TryGrabbedObject(GameObject grabObject)
    {
        //Check for Object if not null Grab it
        if (grabObject == null || !CanGrab(grabObject))
            return;

        grabbedObject = grabObject;
        grabbedObjectSize = grabObject.GetComponent<Renderer>().bounds.size.magnitude;
    }

    //Can grab condition (RigidBody)
    bool CanGrab(GameObject candidate)
    {
        return candidate.GetComponent<Rigidbody>() != null;
    }
    void DropObject()
    {
        grabbedObject.GetComponent<Rigidbody>().velocity = Vector3.forward * 0;
        if (grabbedObject = null)
            return;
        if (grabbedObject.GetComponent<Rigidbody>() != null)
            grabbedObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
        onViewmodel();
    }

    void OnCollisionEnter(Collision collision)
    {
        hitpickupable = true;
    }

    // UPDATE is called once per frame

    void DropObjectWithF()
    {
        //Release Direction and Velocity
        //Set multiplier larger for more force
        grabbedObject.GetComponent<Rigidbody>().velocity = transform.forward * 7;

        //Check if hands are empty
        if (grabbedObject = null)
            return;
        //if holding object
        if (grabbedObject.GetComponent<Rigidbody>() != null)
            //stop object before release
            grabbedObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
    }
   void offViewmodel()
        {
        gun1.SetActive(false);
        gun2.SetActive(false);
        gun3.SetActive(false);
    }
    void onViewmodel()
    {
        gun1.SetActive(true);
        gun2.SetActive(true);
        gun3.SetActive(true);
    }

    void OnCollisionStay(Collision collision)
    {
        grabbedObject.GetComponent<Rigidbody>().velocity = Vector3.forward * 0;
        if (grabbedObject = null)
            return;
        if (grabbedObject.GetComponent<Rigidbody>() != null)
            grabbedObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
    }
    void Update()
    {
        //Assign Input for Grab
        if (Input.GetKeyDown(KeyCode.F))
        {
            if (grabbedObject == null)
                TryGrabbedObject(GetMouseHoverObject(5));
            //Set Grab and Drop as Same button (Right Mouse Button)
            else DropObject();
        }
        if (grabbedObject != null)
        {
            //Set position of grabbed Object after grabbing
            Vector3 newposition = gameObject.transform.position + Camera.main.transform.forward * grabbedObjectSize;
            grabbedObject.transform.position = newposition;

            if (Input.GetKeyDown(KeyCode.F))
            {
                gun1.SetActive(false);
            }
            else
                gun1.SetActive(true);
            }

                if (Input.GetKeyDown(KeyCode.F))
            {
                gun1.SetActive(false);
                gun2.SetActive(false);
                gun3.SetActive(false);
            }
            if (Input.GetKey(KeyCode.V))
            {
                DropObjectWithF();
            }
            if (Input.GetKey(KeyCode.V))
            {
                onViewmodel();
            }
            if (Input.GetKey(KeyCode.G))
            {
                gun1.SetActive(true);
                gun2.SetActive(true);
                gun3.SetActive(true);
            }
        }

    private void StartCoroutine(IEnumerable enumerable)
    {
        throw new NotImplementedException();
    }
}

The easiest way I think to do that would be to add a collision to it rather than a trigger, then instead of using OnCollisionStay you do a distance check in your Update()
You can also use multiple collision boxes and setup the collision matrix to get the behaviour you want, but because you have an Update() already I think my 1st solution would be easier, using Vector3.Distance().