Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

my human.HealthChanged script loop ?

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.

1 answer

✓ Accepted answer

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.

2 comments

0

Thanks dude you saved me !

0

No problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.