My SpeedBoost doesnt deactivate and my Player stays with the SpeedBoost

I wanted to create a SpeedBoost once I enter a Collectable but unfortunately it is not working.
Once I hit the collectable I get my runSpeed. But my runSpeed stays and doesn’t go back to moveSpeed.

For more Information: I can access my moveSpeed and my runSpeed through the Unity Inspector and add a number that will be the move/run Speed of the Player. Before I made the SpeedBoost I added runSpeed on Shift so I can see that it works. I mainly Followed Tutorial on Udemy and tried to add assets etc. of my own.

This is the first question that I am asking so sorry if I didn’t explain something. I am new to Unity and just follow many tutorials. This is my whole Player Controller Script. The SpeedBoost code starts at line 68 basically ends on line 90. But the boostTimer and “boosting” added on start.

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

public class PlayerController : MonoBehaviour
{
    public float moveSpeed;
    public Rigidbody2D rb;
    public float jumpForce;
    public float runSpeed;
    private float activeSpeed;

    public bool isGrounded;
    public Transform groundCheckPoint;
    public float groundCheckRadius;
    public LayerMask whatIsGround;

    public Animator ani;
    private float boostTimer;
    private bool boosting;



   
    // Start is called before the first frame update
    void Start()
    {
        boostTimer = 0;
        boosting = false ;
    }

    // Update is called once per frame
    void Update()
    {
        isGrounded = Physics2D.OverlapCircle(groundCheckPoint.position, groundCheckRadius, whatIsGround); 

       activeSpeed = moveSpeed;
        if(Input.GetKey(KeyCode.LeftShift))
        {
            activeSpeed = runSpeed;
        }
        
        rb.velocity = new Vector2 ( Input.GetAxisRaw("Horizontal") * activeSpeed, rb.velocity.y);

        if (Input.GetButtonDown("Jump"))
        {
            if(isGrounded == true)
            {
               rb.velocity = new Vector2(rb.velocity.x, jumpForce);
            }
            
        } 

        if(rb.velocity.x > 0)
        {
            transform.localScale = Vector3.one;
        }
        if (rb.velocity.x < 0)
        {
            transform.localScale = new Vector3(-1f, 1f, 1f);
        }

        //animation dings
        ani.SetFloat("speed", Mathf.Abs(rb.velocity.x));
        ani.SetBool("isGrounded", isGrounded);
        ani.SetFloat("ySpeed", rb.velocity.y);

        if (boosting)
        {
            boostTimer += Time.deltaTime;
            if(boostTimer >= 3)
            {
                runSpeed = moveSpeed;
                boostTimer = 0;
                boosting = false;
            }
        }

    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "SpeedBoost")
        {
            boosting = true;
            moveSpeed = runSpeed;
            Destroy(other.gameObject);
        }
            
    }

    public void KnockBack()
    {
        rb.velocity = new Vector2(0f, jumpForce * .5f);
        ani.SetTrigger("isHit");

    }
}

New contributor

Crexlo Dev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Assuming that:

activeSpeed is the player’s current movement speed;
moveSpeed is the player’s walking movement speed (constant);
runSpeed is the player’s running movement speed (also constant);

I would assume that in OnTrigger2DSpeed, activeSpeed must be equal to runSpeed, and not moveSpeed – else you just told your code that walking speed is equal to running speed – and then in the next frame you set activeSpeed to moveSpeed that now is equal to running speed.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật