I'm trying to make a script where if the player hits an object, it will change the value of something to true, then wait 5 seconds before it changes it back to false. I want it to wait another 5 seconds if it has been hit before it gets a chance to change the value back to false. However, I'm having trouble with this. My current script continues to change the value to false, even if I hit it again. (It's supposed to wait 5 seconds)
local Animal = script.Parent
local Attacker = Animal.Attacker
local TakingDamage = Animal.IsTakingDamage
script.Parent.Touched:Connect(function(tuc)
if tuc.name == "Blade" then
Attacker.Value = tuc.Parent.Parent.Name
TakingDamage.Value = true
print("TakingDamage")
wait(5)
Attacker.Value = "nil"
TakingDamage.Value = false
end
end)
How can I stop it from setting the value false if it has been hit again? Feel free to ask questions. Help is appreciated.

17 comments
Uhm, this is MY solution.
Uh not really, you think i dont know to use a variable for wait? I came up with this myself bro, its not that hard. Also your script has logical errors and your while loop runs indefinitely, my loops only run if it needs to, much more efficient and everything is contained within the script, no value object needed
Heh, funny, we both know that i was the first that found the solution, oh and also, the longer the script is, the MORE lag it produces.
facepalm
Well, sorry pal, but i don't see any "Logical Errors", except the existence of this "Copycat".
If you don't believe in the fact that a script is capable of producing lag, well, its your problem, 'cause its proved.
Alright fine if you think my programming skills isnt good enough to come up with this solution by myself then so be it, i cant really change your mind.
"don't believe in the fact that a script is capable of producing lag," bruh, when did i even say or imply that
I didn't say that "your programming skills isn't good enough to come up with this solution", our answers are similar, but i was the one who found the solution first.
Alright cool, then i guess it was a misunderstanding, especially when you said " Uhm, this is MY solution."
jesus christ can you grow up, i admitted it was a misunderstanding and you still have to say "have fun with your solution"
Accepted, lets end this.
Alright we cool? We have different ways to achieve the solution,its up to the OP which one he chooses
Both of you chill the f out. It doesn't matter, no one is a "copycat". So stfu and go back to scripting
Tried this script and it works. Thank you!
No problem bro, this was an interesting problem, i always used debounce but never thought to use debounce in a way that resets itself if a player triggers the touched event
Welp, congratulations, i wasted 15 minutes to write my solution.