Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Animation Debounce not creating a cooldown?

Asked by 4 years ago

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?

1 answer

Log in to vote
0
Answered by
DrShockz 233 Moderation Voter
4 years ago

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

0
Ok i'll try it out in a few hours cause school lol packayee 13 — 4y
0
But this does seem like the only good answer packayee 13 — 4y
0
Thanks :) DrShockz 233 — 4y
0
I have one request, can u copy and paste your answer into roblox studio, bind the animation to the animationtrack and test if the debounce works? packayee 13 — 4y
0
Sorry it was late for me :) DrShockz 233 — 4y
Ad

Answer this question