|
| 19 Aug 2016 12:59 PM |
Can anyone help me out? I'm trying to make it print("dead") when the IntValue goes below 0. The weird thing is when the < is replaced with > it prints and works.
(Health is an IntValue)This is the script...
local Health = script.Parent.Health local Part = script.Parent.Parent
if Health.Value <= 0 then print("dead") end
|
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 19 Aug 2016 01:09 PM |
Try this:
local Health = script.Parent.Health local Part = script.Parent.Parent
Health.Changed:connect(function() if Health.Value <= 0 then print("dead") end end) |
|
|
| Report Abuse |
|
|
|
| 19 Aug 2016 01:10 PM |
that if statement you have will only fire once
it makes sense that it fires when it's greater than 0 because that conditional will run right when the game starts, and of course, the enemy is not going to be hit yet
amanda has what you need
Formerly xXTheRobotXx, add 13,349 posts |
|
|
| Report Abuse |
|
|
| |
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 19 Aug 2016 01:16 PM |
No problem.
The Changed event fires whenever a property changes in whatever object you are looking at.
So Health.Changed will be triggered every time the Health.Value property changes.
So every time it changes, you check if it's 0, and if it is then run your code. |
|
|
| Report Abuse |
|
|