Debounce (Help)

Debounce isn’t working, can someone please help me out?

This code is supposed to run an animation, that is working, but the debounce which is supposed to act as a delay isn’t working.

3978f41a4107976808a52151bbf6f4d5

What do u mean by not working?

Can you provide all your code and an error message if applicable?

The problem is there’s not enough context to this post. :smiley:

1 Like

There isn’t an error message. (30 Characters)

I guess you need to do like this

local debounce = false

if debounce then
  if debounce == false then
      debounce = true
      DumbbellSwingAnimTrack:Play()
      wait(3)
      debounce = false
   end
end



Did you wait the 3 seconds before trying it again or does it jusy completely not work
Could the debounce value be set to true or something else?

Add prints to check the script and if it is running. Also if denounce then will not fire if denounce is false.

So basically the code is working, but if you’re constantly clicking, it doesn’t wait 3 seconds before playing the animation again.

if the animation is longer than three seconds then the debounce would have reverted to false before the animation track could finish.

The animation is 1 second long.

Could you show the whole code because just the debounce by itself would not be enough.

2 Likes
if debounce == false then
      debounce = true
      DumbbellSwingAnimTrack:Play()
      repeat wait() until DumbbellSwingAnimTrack.IsPlaying == false -- repeat wait() until it's not playing anymore.
      debounce = false
   end

OR

if debounce == false then
      debounce = true
      DumbbellSwingAnimTrack:Play()
      wait(DumbbelSwingAnimTrack.Length) -- Wait the length of the animation. You could add a + 0.1 if you wanted to wait the length of the animation and 0.1 seconds. (DumbbelSwingAnimTrack.Length + 0.1)
      debounce = false
   end

You could also use the repeat wait() solution for the animation to stop playing. Then add a wait(3) under it for the 3 second delay.

If the anim is not looped u can just do
DumbbellSwingAnimTrack.Stopped:Wait()

1 Like

But whats the problem with my code? I still can’t identify the problem.

Even better :+1:

Good thinking

From my perspective there’s no issue. It’s probably some other logic.

So is this like a bug, if so should I report this?

No, there’s just not enough code or logic provided for us to act on. This looks like a regular debounce. We don’t know what you’re doing externally.

It’s like you’re driving a yellow bus with kids in the back and then the bus suddenly stops moving. You ask the kids what’s wrong by showing them the gas pedal, brake pedal and the steering wheel. But the problem is in the engine itself. You’re just not allowing them to take a look at the bus engine to determine the root of the problem.

1 Like

what a thought out and good analogy

1 Like