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.
humanoid.HealthChanged:Connect(function(CurrentHealth)
wait(5)
print("Test")
end
local timer = 5;
local lastHp = humanoid.Health;
coroutine.wrap(function()
while humanoid.Health > 0 do -- loop until the player dies
repeat
wait(1);
timer -= 1;
until timer <= 0;
-- what you want to do after 5 seconds of no damage
timer = 5;
end
end)() -- create a coroutine and start it immediately
humanoid.HealthChanged:Connect(function(CurrentHealth)
if(currentHealth < lastHp) then -- they took damage
timer = 5; -- reset timer
else
lastHp = currentHealth; -- they healed, set new scope
end
end