I am making a game in which the "player/user" will loose hunger. I want to make it so that when their hunger gets bellow 25 (var f) then their health (var h) will start to decrease by 20 every 5 seconds. But once the hunger goes up above 25, the health stops decreasing. This is why I am using a while event. I am not sure how to make it so the function waits five seconds, and then restarts.
function health() {
h = 500;
displayHealthCount();
while (f <= 25) {
h -= 20;
displayHealthCount();
//I want to make it so it waits for five seconds here
}
}