Basically, what I am trying to do is:
If the player takes damage, it waits 10 seconds for the player to heal.
However, if the player is damaged again, it stops the countdown.
How would I do this?
Here’s my code, by the way.
local healcool = false
function uhoh(hp)
if healcool == false then
healcool = true
wait(10)
healcool = false
human.Health = human.Health + human.Health / 2
end
end
human.HealthChanged:Connect(uhoh)
You can do this pretty simply following these steps:
Create a boolean:
You make a boolean, and check if the player took damage, and if they did, you can set it to true, make a script that waits 10 seconds if the boolean is true, then heal them, and if they took damage again, set it to false.
local healcool = false -- haven't healed yet
local counter = 0 -- counter to see if its been enabled already [default 0]
function Damaged(hp) -- function to tell when they got damaged
if healcool == false then -- if heal cool is false
healcool = true -- then heal cool is true
counter = 1 -- setting counter to 1
end
if counter == 0 and healcool == true then -- if counter is default and heal cool is true
wait(10) -- we wait 10 seconds
human.Health = human.Health + human.Health / 2 -- then we heal
end
if counter == 1 then return end -- if the counter is one t
end
human.HealthChanged:Connect(Damaged)
I haven’t tested this, but I added a counter as an example? You could basically make a way to stop the wait() by adding another local variable to see if its already been damaged.