Cloned gameObjects not set active

public class SpikeDamage : MonoBehaviour
{
    public float speed = 2.0f;

    void Start()
    {
        gameObject.SetActive(false);
    }
    void Update()
    {
        transform.position += -transform.up * speed * Time.deltaTime;
        gameObject.SetActive(true);
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "SpikesDamage")
        {
            Destroy(gameObject);
        }
    }
}
public class CreateSpikeDamage : MonoBehaviour
{
    public float destroy = 5.0f;

    public GameObject spikeDamage;
    public Transform spikeDamagePos;

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            spikeDamage.SetActive(true);
            Destroy(spikeDamage, destroy);
            Instantiate(spikeDamage, transform.position, transform.rotation);
        }
    }
}

I want to spawn a gameObject every time I walk onto a trigger, when I walk onto it at first it does what I want but when I walk onto it again it spawns the clones but they are not active. What am I doing wrong? Thanks!

this might be a problem:

spikeDamage.SetActive(true);
Destroy(spikeDamage, destroy); <— soon you will instantiate destroyed object
Instantiate(spikeDamage, transform.position, transform.rotation);

How could I fix this ? Maybe make another function with the destroy code but what kind of function could I add ?

First of all tell us what you want to achieve.
What is SpikeDamage (also I suggest naming your MonoBehaviours with Component in name, like SpikeDamageComponent)

I basically just want to spawn a gameObject when the player goes into a collider that Is trigger that kills the player and after some time the gameObject gets destroyed those two things work. The only thing that doesn’t work is when I go onto the collider again it doesn’t work the gameObject doesn’t spawn again.

First of all a dont know why are you even messing around with gameObject.setActive In SapikeDamage.
The second thing i dont undesratnad why are you doing this.

  • spikeDamage.SetActive(true);
  • Destroy(spikeDamage, destroy);
  • Instantiate(spikeDamage, transform.position, transform.rotation);

You basically destroy your prefab. What for are you doing this ?

The thing is that you are destroying the prefab instead of destroying the instantiated one.

So it works the first time but the second time you try the prefab is destroyed aka null and when you try to copy it you are just copying a null.

I suggest
GameObject go = Instantiate(spikeDamage, transform.position, transform.rotation);

Then destroy go instead.