Debounce for animation not working

I made a debounce for the animation but it isn’t working
Here is the Script:
local character = script.Parent

local Humanoid = character:WaitForChild(“Humanoid”)

local jumpAnim = Instance.new(“Animation”) – Accessing the animation

jumpAnim.AnimationId = “rbxassetid://13305253140” – Getting the Animation Id

local jumpAnimTrack = Humanoid:WaitForChild(“Animator”):LoadAnimation(jumpAnim) – Making a animation track, so the animation can be loaded onto the Character.

local debounce = false

if Enum.KeyCode.X then

if debounce == false then

debounce = true

jumpAnimTrack:Play()

task.wait(2)

debounce = false

end

end

1 Like

you put the debounce value inside the function, it resets everytime and is false so it doesnt work
put it ouside the function

1 Like

Like this?

local character = script.Parent

local Humanoid = character:WaitForChild(“Humanoid”)

local jumpAnim = Instance.new(“Animation”) – Accessing the animation

jumpAnim.AnimationId = “rbxassetid://13305253140” – Getting the Animation Id

local jumpAnimTrack = Humanoid:WaitForChild(“Animator”):LoadAnimation(jumpAnim) – Making a animation track, so the animation can be loaded onto the Character.

local debounce = false

if debounce == false then

debounce = true

if Enum.KeyCode.X then

jumpAnimTrack:Play()

task.wait(2)

debounce = false

end

end

1 Like

use backticks to format your code

```
code here
```

also is this code in a function? i noticed you used

if Enum.KeyCode.X then

which is kind of pointless

1 Like

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