Apply the same script on multiple objects

Hello! So I’ve been working on the basic mechanics of a top-down shooter game, and now I’m trying to apply some of the scripts and components that work for a single object to multiple objects. However, some of them do not work as expected. For example, I have a health bar UI (canvas in world space) that displays the enemy health. It works perfectly fine for a single enemy, but when I duplicate the enemy object, along with the canvas, the canvas does not function properly. I changed the references so that shouldn’t be the issue. I’m wondering what’s the problem here. Thank you!
(As you can see in the pic, the second health bar does not behave according to the script)


Can you paste the health script here?

hello, the none working one is a duplicate? instantiated at runtime or by code? my bet is that both EnemyHealthBar are referencing to the exact same objects can you add this method to that EnemyHealthBar script and test?

void Start()
{
   slider = GetComponent<Slider>();
   fill = transform.GetComponentInChildren<Image>();
}