Objects with the same script influencing each other

In my game, there are ladders throughout the scene , but they are influencing each other because they have the same script attached to them. What happens is that when there’s only one script enabled, the ladder works just fine, my player can go up and down without a problem , but when I enable the others scripts the ladders simply dont work. How can I make they independent of each other even though I’m using the same script for them?

Here’s the code for anyone who’s wondering:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LadderBehaviour : MonoBehaviour
{
    [SerializeField]
    private PlayerMovement player;
    [SerializeField]
    private Transform rayPos;
    [SerializeField]
    private LayerMask playerLayer;
    private float vMove;
    [SerializeField]
    private int speed;
    private float gravity;
    RaycastHit2D hitInfo;
    [SerializeField]
    private Vector2 boxSize;
    private bool isDescending;
    private bool isStopped;

    private void Start()
    {
        gravity = player.GetComponent<Rigidbody2D>().gravityScale;
    }

    private void Update()
    {
        hitInfo = Physics2D.BoxCast(rayPos.position,new Vector2(boxSize.x, boxSize.y), 0f, Vector2.down,1f,playerLayer);
        vMove = Input.GetAxisRaw("Vertical");

        if (hitInfo.collider != null && Input.GetKeyDown(KeyCode.UpArrow))
        {
            player.ladderUp = true;
        }

        if (player.ladderUp && player.GetComponent<Rigidbody2D>().velocity.y < 0)
        {
            isDescending = true;
            if(isDescending && player.isGrounded)
            {
                player.ladderUp = false;
            }
        }

        if(player.ladderUp && player.GetComponent<Rigidbody2D>().velocity.y == 0)
        {
            isStopped = true;
            if (isStopped)
            {
                player.stopClimbing = true;
            }
        }
        else
        {
            player.stopClimbing = false;
        }
      
        if(player.ladderUp && Input.GetKeyDown(KeyCode.Space) || hitInfo.collider == null)
        {
            player.ladderUp = false;
        }
    }

    void FixedUpdate()
    {
        if (player.ladderUp)
        {
            player.GetComponent<Rigidbody2D>().velocity = new Vector2(player.GetComponent<Rigidbody2D>().velocity.x, vMove * speed);
            player.transform.position = new Vector3(transform.position.x, player.transform.position.y, player.transform.position.z);
            player.GetComponent<Rigidbody2D>().gravityScale = 0;
        }
        else
        {
            player.GetComponent<Rigidbody2D>().gravityScale = gravity;
        }
    }

    private void OnDrawGizmosSelected()
    {
        Gizmos.DrawWireCube(rayPos.position, new Vector2(boxSize.x, boxSize.y));
        Gizmos.color = Color.white;
    }
}