How to access the variable of a parent's script?

I realize this question has been asked, but I’ve tried all of the solutions I can find to no avail. I’m wondering if there is something about my circumstances that is causing the issue. I have a fire particle effect that gets instantiated on an object as it’s child, and then attempts to lower the health variable of it’s parent. I’ve tried the following code:

gameObject.transform.parent.GetComponent(EnemyData).health -= 3;

and

transform.parent.GetComponent(EnemyData).health -= 3;

and

gameObject.transform.parent.gameObject.GetComponent(EnemyData).health -= 3;

etc

You could simply use the second alternative:

transform.parent.GetComponent(EnemyData).health -= 3;

But since you’re getting null reference errors, either the object has no parent or its parent has no EnemyData script - if health was misspelled, the error would be different (something like health is not part of EnemyData or similar). Double check the hierarchy, or add debug lines to know what’s happening:

var daddy: Transform = transform.parent;
if (!daddy) print("Object has no parent");
var script: EnemyData = daddy.GetComponent(EnemyData);
if (!script) print("Parent has no EnemyData script");
script.health -= 3;