I need this to make sure its always dragable, some strange happenings are making it not draggable sometimes please fix and return full script fixed

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using System.Collections;

public class UIDragAndReturn : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
    private RectTransform rectTransform;
    private CanvasGroup canvasGroup;
    private Canvas canvas;

    private Transform originalParent;
    private int originalSiblingIndex;
    private Vector3 originalPosition;

    private Vector2 pointerOffset; // Offset between pointer and dragged object's pivot, in canvas local space.

    private Coroutine returnCoroutine;

    private void Awake()
    {
        rectTransform = GetComponent<RectTransform>();
        canvasGroup = GetComponent<CanvasGroup>();

        if (canvasGroup == null)
        {
            canvasGroup = gameObject.AddComponent<CanvasGroup>();
        }

        canvas = GetComponentInParent<Canvas>();
        if (canvas == null)
        {
            Debug.LogError("UIDragAndReturnFixed: No Canvas found in parent hierarchy.");
        }
    }

    public void OnBeginDrag(PointerEventData eventData)
    {
        if (returnCoroutine != null)
        {
            StopCoroutine(returnCoroutine);
            returnCoroutine = null;
        }

        originalParent = transform.parent;
        originalSiblingIndex = transform.GetSiblingIndex();
        originalPosition = rectTransform.anchoredPosition;

        // Reparent to canvas root first so position and pointer calculations occur in correct space
        transform.SetParent(canvas.transform, worldPositionStays: true);
        transform.SetAsLastSibling();

        // Calculate pointer offset relative to the canvas in local space
        Camera cam = eventData.pressEventCamera != null ? eventData.pressEventCamera : canvas.worldCamera;

        Vector2 localPointerPosInCanvas;
        RectTransform canvasRectTransform = canvas.transform as RectTransform;

        // Convert screen point to local point in canvas
        if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRectTransform, eventData.position, cam, out localPointerPosInCanvas))
        {
            // pointerOffset = mouse position in canvas local space - element's anchoredPosition
            pointerOffset = localPointerPosInCanvas - rectTransform.anchoredPosition;
        }
        else
        {
            pointerOffset = Vector2.zero;
        }

        // Disable raycast blocking so events can pass through while dragging
        canvasGroup.blocksRaycasts = false;
    }

    public void OnDrag(PointerEventData eventData)
    {
        Camera cam = eventData.pressEventCamera != null ? eventData.pressEventCamera : canvas.worldCamera;
        Vector2 localPointerPosInCanvas;
        RectTransform canvasRectTransform = canvas.transform as RectTransform;

        // Convert screen point to local point on canvas
        if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRectTransform, eventData.position, cam, out localPointerPosInCanvas))
        {
            // Position the dragged element so that the pointer stays at the same point inside the element
            rectTransform.anchoredPosition = localPointerPosInCanvas - pointerOffset;
        }
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        canvasGroup.blocksRaycasts = true;
        returnCoroutine = StartCoroutine(ReturnToOriginalParent());
    }

    private IEnumerator ReturnToOriginalParent()
    {
        Vector3 startPos = rectTransform.anchoredPosition;

        // Set parent back first, restoring sibling index so layout group works properly
        transform.SetParent(originalParent, worldPositionStays: true);
        transform.SetSiblingIndex(originalSiblingIndex);

        float elapsed = 0f;
        float duration = 0.25f;

        while (elapsed < duration)
        {
            elapsed += Time.deltaTime;
            rectTransform.anchoredPosition = Vector3.Lerp(startPos, originalPosition, elapsed / duration);
            yield return null;
        }

        rectTransform.anchoredPosition = originalPosition;

        returnCoroutine = null;
    }
}