Object won't break when the health is at 0

Hi, I am very new to attributes so I could just be extremely dumb.

Currently working on a mining system with attributes, blah blah whatever. When the objects health reaches exactly 0, it doesn’t destroy it. Instead, it will destroy it when you go below zero.

What?

Piece of code that handles what happens when an objects health reaches 0:

if targetHealth <= 0 then

Not sure how much this will affect my game but might as well try to see if there is a fix for it.

strange–and with that logic, <=1 would have the same effect?

1 Like

That fixed it, don’t know why I didn’t think of that. I just woke up so maybe that’s why.

Pretty strange considering the same code will work with Int/Number values.

Yea it doesn’t make sense, I would have to think that perhaps attribute value is off by decimals for whatever reason? you can try and print the value on changed event (when ur checking the health) and see what it says

image

Doesn’t look like it’s off at all.

Edit: Seems like the print statement isn’t accurate either. When the health is at 9, it prints it is at 10!

Edit 2: Sort of fixed it by doing

print("Health of target - "..targetHealth - toolDamage)

And you are changing the attribute like Health:SetAttribute(targetHealth-ToolDamage) right?

you can also use math.floor but i don’t see decimals so idk what is going on

ex:

math.floor(targetHealth-ToolDamage)

Here is the code:

target.Parent:SetAttribute("Health", targetHealth - toolDamage)

try using math.floor for the result and see if it does anything

if that doesn’t fix anything I have no idea how to fix it

Looks like it messed up the print statements again. Don’t really know what’s going on but thanks so much for the help! :grin:

1 Like