So, after repeatedly trying to fix this problem on my own, I decided to ask you. Here's the thing: I tried to do a counter attack, like in "smash bros" for a fighting game. And it works, when I press the key, it do the animation , BUT, each time i take damage the counter attack loop.
debounce = true if debounce == true and human.HealthChanged:Connect(function(health) human.Health = human.MaxHealth human:LoadAnimation(script.L):Play() debounce = false end) then end
Any suggestion ? Thanks for reading, AKT_Arthas.
The debouce should be inside the event. You may also need to manage the animation by stopping it if needed but that is something you would need to work out.
An example of a debounce.
local deb = false human.HealthChanged:Connect(function(health) if deb then return end deb = true -- code deb = false end)
Better still you often need to code this over and over so having a function to add a debounce for you may help.
local function addDeb(f) local deb = false return function(...) if deb then return end deb =true f(...) -- run function deb = false end end -- add debounce to function human.HealthChanged:Connect(addDeb(function(health) -- code end))
Hope this helps.