setInterval/setTimeout is tricky, since it will execute even when the tab is minimized or not in focus. It can be used but even better is to use your own timer inside your scripts update method.
Check this post on how to get started in measuring time, you can use this timer then to apply damage after a cooldown period has finished.