Homing bullet error when player die

The error is because the homing bullets don’t have a target when the player dies and it comes with an error, please help me fix

How do I fix this?

Bullet script:

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

[RequireComponent( typeof(Rigidbody2D) )]
public class HomingMissile : MonoBehaviour
{
	public Transform target;
	public float speed = 5f;
	public float rotateSpeed = 200f;
	private Rigidbody2D rb;

	void Start()
	{
		target = GameObject.FindGameObjectWithTag("Player").transform;
		rb = GetComponent<Rigidbody2D>();
	}

	void FixedUpdate()
	{
		Vector2 direction = (Vector2)target.position - rb.position;
		direction.Normalize();
		float rotateAmount = Vector3.Cross(direction, transform.up).z;
		rb.angularVelocity = -rotateAmount * rotateSpeed;
		rb.velocity = transform.up * speed;
	}
	
}

turn fixed update to this:

void FixedUpdate ()
{
    if(player!=null)
    {
        Vector2 direction = (Vector2)target.position - rb.position;
        direction.Normalize();
        float rotateAmount = Vector3.Cross(direction, transform.up).z;
        rb.angularVelocity = -rotateAmount * rotateSpeed;
        rb.velocity = transform.up * speed;
    }
}

so that direction will only be calculated if player exists. your code is trying to find the direction to target even when the target is gone. Thus null exception.

Also can’t you just destroy the bullet when player dies? Check for player in the update and call Destroy(gameobject) if player is not found. Or is there a reason why you can’t destroy the bullet when player dies?