Bullet not affecting health

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

public class Gun : MonoBehaviour
{
public Transform firepoint;
public GameObject bulletPrefab;
void Start()
{

}

// Update is called once per frame
void Update()
{
    if (Input.GetButtonDown("Fire1"))
    {
        Shoot();
    }
}
void Shoot()
{
    Instantiate(bulletPrefab, firepoint.position, firepoint.rotation);
}

}

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

public class Enemy : MonoBehaviour
{
public int health = 100;

void Start()
{
    
}

// Update is called once per frame
void Update()
{
    
}

/* void OnTriggerEnter(Collider hit)
{
if (hit.gameObject.tag == “KillZone”)
{
Destroy(gameObject);
}
}*/
public void TakeDamage(int damage)
{
health -= damage;
if (health <= 0)
{
Die();
}
}
void Die()
{
Destroy(gameObject);
}
void OnTriggerEnter(Collider other)

{

    Bullet bullet = other.GetComponent<Bullet>();

    if (bullet != null)
    {
        TakeDamage(Bullet.damage);
    }

    // Destroy(gameObject);

}

}

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

public class Bullet : MonoBehaviour
{
public float speed = 20f;
public static int damage = 40;
public Rigidbody rb;

void Start()
{
}
void OnTriggerEnter(Collider hitInfo)
{
    Enemy enemy = hitInfo.GetComponent<Enemy>();
   // BossHealth boss = hitInfo.GetComponent<BossHealth>();

    if (enemy != null)
    {
        enemy.TakeDamage(damage);
    }
    Destroy(gameObject);

   /* if (boss != null)
    {
        boss.TakeDamage(damage);
    }
    Destroy(gameObject);
   */
}
// Update is called once per frame
void Update()
{
    transform.Translate(Vector3.forward * speed * Time.deltaTime);
    Destroy(gameObject, 2);
}

}

You are testing for GetComponent() being null. Trouble is I can’t validate that because I can’t see your GameObject. However, that’s not the normal way of testing. Better to give Bullet a Tag of “Bullet” and then write:

if (other.gameObject.CompareTag("Bullet"))
{
    TakeDamage(Bullet.damage);
}

However, there may be other issues, given that we can’t see all the components. Only one of Bullet and Player can have “is Trigger” and one or both must have a RigidBody. I see you’ve declared rb in the Bullet class but you don’t seem to be using it. Finally, if this is a 2D game, you should be using the 2D versions of the Physics Classes.

If I’m wide of the mark, let us have some more info and we’ll see what we can do…