Scripts not running after adding an if statement, how do i fix this?

I made a similar post here I need help with scripting which i havent been able to fix
but im experiencing the problem in other scripts as well



before adding the if statement the code works perfectly

which if statement are you talking about? there are multiple if-statements in both pictures

i forgot to point those out ill fix it

i fixed it
theres arrows pointing to the specific ones

Are you ever damaging the enemy? It isn’t going to pass unless health is smaller than maxHealth. Maybe you want to use if health <= maxHealth to check if health is smaller or equal to maxHealth?

ok thanks and I think i spotted one thing on the second image

local Health = script.Parent.Enemy.Health
local MaxHealth = script.parent.Enemy.MaxHealth
if Health < MaxHealth then...

what are you storing the health and maxhealth values in? number values or attributes? to even get those values, you have to call certain functions/properties .Value or :GetAttribute()

im using the humanoid(renamed to ‘Enemy’) to store the health and maxhealth values

ah, ok. do you get any error messages when running the scripts? if so, you should add those to the post

it doesnt show any errors for either of the scripts

try printing out the MaxHealth and Health values to see if the health really is lower than the maxhealth

nothing prints out when i do print(health) or maxhealth

That means the conditions of those if statements aren’t being satisfied.

i tried it again and it printed

Then the script is running, just not as how you intended.

ive gotten the script to work with an equal sign, but i dont know how to get it to start once it takes damage.


is there a way to have the script run again after damage is taken?