So, for the third time, I made a local script that plays an animation when R is pressed, along with a function for debounce, so the animation is not spammable. Here is the animation debounce function, it does not change the value for debounce, but it runs waits according to the parameters. (LocalScript)
local function WaitDebounce(AnimationTrack,DebounceLength) repeat wait() until AnimationTrack.IsPlaying == false wait(DebounceLength) end
Now, for the local script that runs the animations:(Same local script as before)
--Humanoid is already defined bc im too lazy to write local Attack = game.ReplicatedStorage.Attack local AttackTrack = Humanoid:LoadAnimation(Attack) local UIS = game:GetService("UserInputService") local AttackDebounce = false UIS.InputBegan:Connect(function(Input) if Input.KeyCode == Enum.KeyCode.R and AttackDebounce == false then AttackTrack.Looped = false AttackTrack:Play() AttackDebounce = true WaitDebounce(AttackTrack,0.5) AttackDebounce = false end end)
When I run the scripts, everything works completely fine except for the Debounce. Does anybody have a solution?
Hello! Hope your having a great day :)
It seems you are playing the animation before the debounce
, which I don't usually do, so I'd add the debounce
at the very start and end of the function.
Like so:
--Humanoid is already defined bc im too lazy to write local Attack = game.ReplicatedStorage.Attack local AttackTrack = Humanoid:LoadAnimation(Attack) local UIS = game:GetService("UserInputService") local AttackDebounce = false UIS.InputBegan:Connect(function(Input) if Input.KeyCode == Enum.KeyCode.R and AttackDebounce == false then AttackDebounce = true AttackTrack.Looped = false AttackTrack:Play() wait(Attack.Length + 0.5) -- replaced with whatever WaitDebounce is. AttackDebounce = false end end)
I'm not too sure if that'll work so please comment if it doesn't :)
Thanks for reading, - DrShockz