Debounce not working at first, then works as supposed to

So I’m creating a combat system where every time you click, it’ll combo and play another animation if clicked in time.

The problem I’m facing is that I have a debounce in place that doesn’t work until ALL animations of the combo have been played, it just spams all attack animations at first, then works properly afterwards.

I’ve looked through the devforum for this specific situation, but I couldn’t find anything like this, hence why I’m making this post.

LocalScript in Character:

UIS.InputBegan:Connect(function(input)
	if IsStunned.Value or attacking.Value then
		return
	end
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if not attacking.Value and not blocking.Value then
			attacking.Value = true
			
			if Running.Value then
				runAttack()
				attacking.Value = false
				return
			end
			
			attack()
			
			attacking.Value = false
		end
	end
	
	if input.KeyCode == Enum.KeyCode.F then
		block()
	end
end)

Video of bug:
https://gyazo.com/c6ddde90856fa6647047013a47a1f864

The “attacking” boolean is something that other scripts utilize as well, checking if the player is attacking or not.

I have tried:

  • Making sure the boolean isn’t affected in other scripts

Any and all help or suggestions are appreciated!

2 Likes

You seem to check if they are attacking or blocking but only deal with the running case inside the logic for attacking and blocking. So if they are running, and they attack, this function will enter the MouseButton1 part when they are running (because attack is set to false) then if they click again the function will re-enter because attacking is now false but running could still be true so it returns.

i removed that block of code and the bug still persists

It was not my suggestion to remove it, it was my suggestion that logic around the order and nature that these events and logic trees are being created could be flawed with one piece of logic only being dealt with inside another piece of logic that is reliant on two parameters. Removing that code above will undoubtedly not work at all, you have to sit and think in your mind how these events could be fouling one another.

ah, i misunderstood a little, i just wanted to see if by removing that block of code it could lead somewhere. ill switch up the orders and events to see where everything fits

It’s most likely possible that one of the values isn’t defaulted correctly. What is the value of them before and after it works correctly?

well, i did just figure out that the value that’s messing up everything is “attacking”, specifically whenever attacking’s Value is defined as false. The values definitely work, but its as if the function gets to “attacking = false” too quickly.

being more specific, when i do attack for the first time, attacking is false despite it being set to true when attacking, and only until all animations are used attacking will be correctly set to true during attacks

Interestingly, it didn’t have to do anything with how the values were handled, i loaded all the animations before calling the attack functions and it worked perfectly. I appreciate all the help given regardless.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.