Help checking damage

Good day, guys! I’m new to scripting and, once again, 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 it’ll have to wait another 5 seconds for the script to do something.

1 Like

In order to check whether the player hasn’t taken any damage, simply check if the health is 100%. (base is 100 unless modified) Then, if the health is no longer at 100, then you could add a 5 second debounce until it can continue.

--local script
local Player = game.Players.LocalPlayer 
local Character = Player.Character or Player.CharacterAdded:Wait() 
local humanoid  = Character:WaitForChild("Humanoid") 

local d ; 
humanoid.HealthChanged:Connect(function(CurrentHealth)
    d = true 
    wait(5) 
    d = false 
end)

Here after this you can check if d is equal to true and if it is that means the player has been damaged in the last 5 seconds and else perform a task.

This is exactly what I did but every time the function is ran, it will ran it a multiple amount of times dependent on health changed function. Let’s say I ran this function 2x within 5 seconds it would run it 2x, I only want it to actually run it 1x within the 5s not a multiple amount of times, so basically: If the player is damaged again within the 5s the waiting time will be back to 5s, the thing with the wait is that it continues separately and will return the amount of times it triggers. I’m not sure if this explanation make sense to you, hopefully it will. I know I should’ve said this earlier.

 humanoid.HealthChanged:Connect(function(CurrentHealth)
    d = true wait(5) d = false 
    print("d = false")
end)

This questino has already been solved via: [Here]