Script is only working on original object

Whenever I try to duplicate the object, it will not take away health from the bar, but the original one will.

        {
            healthBar.transform.position = new Vector2(healthPos, 30);
            healthBar.GetComponent<RectTransform>().sizeDelta = new Vector2(healthLength, 30);
            if (decreasingHealth == true)
            {
                if (damageAmount >= hitValue)
                {
                    decreasingHealth = false;
                    damageAmount = 0;
                }
                else
                {
                    damageAmount += 0.5f;
                    healthLength -= 0.5f;
                    healthPos -= 0.25f;
                    Debug.Log("Damage Taken");
                }
            }

            if (increasingHealth == true)
            {
                if (damageAmount >= hitValue * 2)
                {
                    increasingHealth = false;
                    damageAmount = 0;
                }
                else
                {
                    damageAmount += 0.5f;
                    healthLength += 0.5f;
                    healthPos += 0.25f;
                    
                }
            }
        }
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {
            attackTrigger = true;
        }
            
    }

    void OnTriggerExit(Collider other)
    {
        if (other.tag == "Player")
        {
            attackTrigger = false;
        }
            
    }


    IEnumerator InflictDamage()
    {
        isAttacking = true;
        yield return new WaitForSeconds(1.1f);
        GlobalHealth3.currentHealth -= 5;
        decreasingHealth = true;
        yield return new WaitForSeconds(0.9f);
        isAttacking = false;
    }

}

I’ve been browsing for hours on ways to fix this and I can not seem to find an answer to why this has been happening. any ideas?

Can you provide a bit more context? For instance, how you are duplicating the object, and where this script exists? It’s difficult to understand exactly what your problem is from just looking at the script.

The rest of this script may help, too.

Screenshots (or even a video!) would be perfect.

Also, if the copy is supposed to be losing health, do you see the original version lose health by any chance? Wondering if it’s got a bad reference.

Okay, so I discovered that it removes health within the script of the healthbar, where it should be going down and it says it is within the script. Yet on the actual gameobject for the healthbar within the canvas it is not changing on attack from any entity other than the original enemy ai.