Line Renderers tied to ball keep teleporting/glitching after instantiate

Hi, I’m trying to create a catapult simulating type game where I attach 2 spring joints to a ball and attach line renderers to two cylinders either side of it, I have made a script that upon the release of a ball spawns another identical ball prefab and reattaches the line renderers to the new ball. One the first throw of the ball this works fine however once a new one is loaded in the linerenderers keep switching between two positions (sometimes it will switch between the intended position, and then a fair bit in front of the ball). I have no idea why any of this is happening so any help would be greatly appreciated. My script is attached below.
Thanks.

using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BallHandler : MonoBehaviour
 {
     public GameObject catapultLeft;
     public GameObject catapultRight;
 
     public GameObject ballPrefab;
     private Vector3 ballSpawnPos;
     private int ballCounter = 0;
 
     // Start is called before the first frame update
     void Start()
     {
         ballSpawnPos = GameObject.Find("Sphere").transform.position;
     }
 
     // Update is called once per frame
     void Update()
     {
         if (GameObject.Find("Sphere").GetComponent<SwipeDetect>().newBall)
         {
             GameObject.Find("Sphere").name = "thrown" + ballCounter.ToString();
             GameObject newBall = Instantiate(ballPrefab, ballSpawnPos, Quaternion.identity);
             newBall.name = "Sphere";
             newBall.GetComponent<SwipeDetect>().catapultLeft = catapultLeft;
             newBall.GetComponent<SwipeDetect>().catapultRight = catapultRight;
             catapultLeft.GetComponent<LineRenderer>().enabled = true;
             catapultRight.GetComponent<LineRenderer>().enabled = true;
             Destroy(GameObject.Find("thrown" + ballCounter.ToString()).GetComponent<SwipeDetect>());
 
             ballCounter++;
         }
     }
 }

I’m guna be real with you man, seeing so many GameObject.Find()'s is really scaring me. Not only is it not good practice and very inefficient, but I’ll bet its contributing to your issue (I know you have the logic in there to only ever have one object named sphere but still it scares me). I highly recommend keeping a hard reference to the object you are trying to use for the line renderer rather than re-finding it every frame. Also if you want me to list the (hundreds) of reasons why GameObject.Find is a bad function to use then I can, but for now take my word for it that you should really never use it except for super quick prototyping.

 using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class BallHandler : MonoBehaviour
  {
      public GameObject catapultLeft;
      public GameObject catapultRight;
  
      public GameObject ballPrefab;
      private Vector3 ballSpawnPos;
      private int ballCounter = 0;

      public GameObject currentBall;

  
      // Start is called before the first frame update
      void Start()
      {
          //This is the only call of GameObject.Find() that could maybe be ok
          currentBall = GameObject.Find("Sphere");
          ballSpawnPos = currentBall.transform.position;
      }
  
      // Update is called once per frame
      void Update()
      {
          if (currentBall.GetComponent<SwipeDetect>().newBall)
          {
              Destroy(currentBall.GetComponent<SwipeDetect>());

              GameObject newBall = Instantiate(ballPrefab, ballSpawnPos, Quaternion.identity);
              newBall.GetComponent<SwipeDetect>().catapultLeft = catapultLeft;
              newBall.GetComponent<SwipeDetect>().catapultRight = catapultRight;
              catapultLeft.GetComponent<LineRenderer>().enabled = true;
              catapultRight.GetComponent<LineRenderer>().enabled = true;

              currentBall = newBall;
  
              ballCounter++;
          }
      }
  }

Do the same sorta deal in the script that sets the line renderer position (get a reference to this script and look at the currentBall variable). If this doesn’t fix your issue then we will have to dig into more of your code.
**
Also as a side note, you can run into performance problems by calling GetComponent() in your update method. Try only calling it once when you spawn an object or enable a script, and saving the result in a private variable. This is less of an issue than GameObject.Find though…