How to check whether player hasn't taken any damage within 5s?

I’m in need of assistance. How do you know whether the player hasn’t taken any damage in the last five seconds? and if that player takes damage again within the 5s it’ll have to wait another 5 seconds for the script to do something,.

This script works fine but it continues even though the player has taken damage within 5s, it doesn’t wait again for 5s. I’m not sure if this explanation made sense but hopefully you got some of it.

-- Variables are already added, just didn't include it in this script.
1 Like

Something like this can be achieved VIA a loop:

local timer = 5;
local lastHp = humanoid.Health;
    while humanoid.Health > 0 do -- loop until the player dies
            timer -= 1;
        until timer <= 0;
        -- what you want to do after 5 seconds of no damage
        timer = 5;
end)() -- create a coroutine and start it immediately

    if(currentHealth < lastHp) then -- they took damage
        timer = 5; -- reset timer
        lastHp = currentHealth; -- they healed, set new scope

Thank you for this, but how do you make the loop run again if the player has been damaged, the loop seems to stop if the timer has reached 0

I’ve added a loop that will continue until the player dies. Please check it now.

Did you post the same question in ScriptingHelpers?

Thank you so so so much, I’ve been struggling for a few hours on how do I do this, I’m not that good at scripting.

Yeah, I sort of did then I thought the website was down since it was showing me a message that it’s offline. I should probably delete it

Well, you might want to post a link to this thread there, so someone in the future can see the solution.

1 Like

BTW yall dont have to do ; he only did it because he is use to doing it because of a different language :slight_smile: