OnTriggerStay2D Broken

HEY!
I have a problem in my game. so i wanted to make a lever in the game that would activate something or trigger and animation. and it worked BUT, I Used the onTriggerStay2D Function to know if i am colliding with the lever and if i am and i press a button. it triggers the thing or activates an object.
and it randomly stops working for some reason. its just like they weren’t colliding. and then they randomly work again. i searched and tried to fix it. (BTW I tried making the Rigidbody Never sleep) and nothing worked.
i need help

here is the really bad code if u want to look at it

private void OnTriggerStay2D(Collider2D collision)
{
    //Activating / Deactivating objects
    if (activateSomeThing && objectActivated == false && Input.GetKeyDown(KeyCode.E) && collision.CompareTag("Player"))
    {
        objectToActivate.SetActive(true);
        objectActivated = true;
        leverAnimator.SetBool("Open", true);
    }
    else if (activateSomeThing && objectActivated == true && Input.GetKeyDown(KeyCode.E) && collision.CompareTag("Player"))
    {
        objectToActivate.SetActive(false);
        objectActivated = false;
        leverAnimator.SetBool("Open", false);
    }

    //Toggling Animations
    if (toggleAnimations && animationToggled == false && Input.GetKeyDown(KeyCode.E) && collision.CompareTag("Player") && _bool)
    {
        animatorToToggle.SetBool(boolOrTriggerName, true);
        animationToggled = true;
        leverAnimator.SetBool("Open", true);
    }
    else if (toggleAnimations && animationToggled == true && Input.GetKeyDown(KeyCode.E) && collision.CompareTag("Player") && _bool)
    {
        animatorToToggle.SetBool(boolOrTriggerName, false);
        animationToggled = false;
        leverAnimator.SetBool("Open", false);
    }
    if (toggleAnimations && animationToggled == false && Input.GetKeyDown(KeyCode.E) && collision.CompareTag("Player") && trigger)
    {
        animatorToToggle.SetTrigger(boolOrTriggerName);
        animationToggled = true;
        leverAnimator.SetBool("Open", true);
    }
    else if (toggleAnimations && animationToggled == true && Input.GetKeyDown(KeyCode.E) && collision.CompareTag("Player") && trigger)
    {
        animatorToToggle.SetTrigger(boolOrTriggerName);
        animationToggled = false;
        leverAnimator.SetBool("Open", false);
    }
}
private void OnTriggerEnter2D(Collider2D collision)
{
    //Activating / Deactivating objects
    if (activateSomeThing && objectActivated == false && Input.GetKeyDown(KeyCode.E) && collision.CompareTag("Player"))
    {
        objectToActivate.SetActive(true);
        objectActivated = true;
        leverAnimator.SetBool("Open", true);
    }
    else if (activateSomeThing && objectActivated == true && Input.GetKeyDown(KeyCode.E) && collision.CompareTag("Player"))
    {
        objectToActivate.SetActive(false);
        objectActivated = false;
        leverAnimator.SetBool("Open", false);
    }

    //Toggling Animations
    if (toggleAnimations && animationToggled == false && Input.GetKeyDown(KeyCode.E) && collision.CompareTag("Player") && _bool)
    {
        animatorToToggle.SetBool(boolOrTriggerName, true);
        animationToggled = true;
        leverAnimator.SetBool("Open", true);
    }
    else if (toggleAnimations && animationToggled == true && Input.GetKeyDown(KeyCode.E) && collision.CompareTag("Player") && _bool)
    {
        animatorToToggle.SetBool(boolOrTriggerName, false);
        animationToggled = false;
        leverAnimator.SetBool("Open", false);
    }
    if (toggleAnimations && animationToggled == false && Input.GetKeyDown(KeyCode.E) && collision.CompareTag("Player") && trigger)
    {
        animatorToToggle.SetTrigger(boolOrTriggerName);
        animationToggled = true;
        leverAnimator.SetBool("Open", true);
    }
    else if (toggleAnimations && animationToggled == true && Input.GetKeyDown(KeyCode.E) && collision.CompareTag("Player") && trigger)
    {
        animatorToToggle.SetTrigger(boolOrTriggerName);
        animationToggled = false;
        leverAnimator.SetBool("Open", false);
    }
}

}

This code blows my mind. I don’t understand why you’d need this much spaghetti code to do something seemingly very simple. Seems like you want to trigger something to happen with an animation on a specific collision. If you explain what you want to happen more clearly, I can try to help you, otherwise I don’t think you’ll have much luck on here.

When a marble collides with the two side walls I use OnTriggerEnter2D() and rotate the angle so it bounces off the walls at an angle. When the marble collides with the top wall it basically freezes, at which point I remove the rigidbody component and set a “topObjects” tag