# HP heal after set time not working (setInterval();)

**URL:** <https://forum.kirupa.com/t/hp-heal-after-set-time-not-working-setinterval/311603>\
**Category:** programming\
**Created:** [July 12, 2010, 5:55am UTC](https://forum.kirupa.com/t/hp-heal-after-set-time-not-working-setinterval/311603 "2010-07-12T05:55:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naezo](https://avatars.discourse-cdn.com/v4/letter/n/b782af/32.png) [@Naezo](https://forum.kirupa.com/u/Naezo)\
**Post date:** [July 12, 2010, 5:55am UTC](https://forum.kirupa.com/t/hp-heal-after-set-time-not-working-setinterval/311603/1 "2010-07-12T05:55:50Z")

</div>

You guy’s have saved me once not to long ago, I could use that again here 😃

So, my problem is I have set up a script for a HP bar, and now I want to set up a script that will replenish the character’s HP after a set amount of time. (IE. 2 seconds.) I was reading about setInterval(); and clearInterval(); and it seemed to be the best thign to use, but I can’t get it to work.

here is my code

```auto
CurrHP = 10;
HP = 50;
clearInterval(autoheal);
var autoheal = setInterval(function () {
    if (CurrHP<HP) {
        CurrHP += 5;
    }
}, 2000);
trace(CurrHP);

```

any help would be great!

Thanks in advance,  
-Naezo
