hey i have a problem where i cant detect things if the is trigger is on

i have already looked this up on this site and have not found a solution.

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

public class touch : MonoBehaviour
{
public follow script;

[SerializeField] private int fastspeed;

private void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.gameObject.CompareTag("player"))
    {
        script.speed = fastspeed;

    }

}

Hi @waffle_Yumy
If your collider is in trigger mode you need to use the following method. Please check if it works.

 [SerializeField] private int fastspeed;
 private void OnTriggerEnter2D(Collider2D collider)
 {
     if (collision.gameObject.CompareTag("player"))
     {
         script.speed = fastspeed;
     }
 } 

Hope it helps!