Trigger Particle Effect On Enemy Death

I’m an artist,but have been asked to do some coding for my uni course so fairly baffled by all this coding stuff and have been following some tutorials.I have two scripts for my enemy, one marked as health that can be reference by both player and enemy, and an enemy health script that also controls score management on it. On enemy death I get this error message:

The variable deathEffect of EnemyHealth has not been assigned.
You probably need to assign the deathEffect variable of the EnemyHealth script in the inspector.

HEALTH

using UnityEngine;

public class Health : MonoBehaviour
{

  

    [SerializeField]
    protected int health;

    [SerializeField]
    protected int maxHealth;

    public GameObject deathEffect;

        public void TakeDamage(int amount)

    {
        health -= amount;
        health = Mathf.Clamp(health, 0, maxHealth);

        if (health <= 0)

        {
            Die();
        }

    }

    public virtual void Die()

    {
        Destroy(gameObject);
         Instantiate(deathEffect);
        Destroy(deathEffect, 2);
    }

    public void MultiplyHealth(int amount)

    {
        health += amount;

ENEMY HEALTH

using UnityEngine.UI;
using UnityEngine;
using System;
   public class EnemyHealth : Health
{
    public int scoreValue;
  
   

    public override void Die()

       
    {
      
      

      


        GameObject.Find("ScoreManager").GetComponent<ScoreManager>().AddToScore(scoreValue);

        base.Die();
    }
}

any help would be really appreciated as I cant move on until I fix this issue.

You’re making a simple but classic beginner mistake of instantiating your prefab, but not holding onto the reference you get back from Instantiate, then accidentally destroying your original prefab.

Try this in your Die function:

        Destroy(gameObject);
        GameObject deathEffectClone = Instantiate(deathEffect);
        Destroy(deathEffectClone, 2);

You can help reduce these sorts of issues by using names like deathEffectPrefab instead of just deathEffect, that way the error would be more rapidly spotted.

Thanks for the quick reply, I’ve made the changes but its still not running the particle system on the die function, I’m still not sure to as why.

Is it the same error as before or now it’s just not spawning the particles instead?