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

How do I add debounce to an animation script?

Asked by
Lyphios 77
5 years ago
Edited 5 years ago

I've got a script that randomly picks one out of three animations when the player clicks, and I've tried to add debounce to it. Here's the product:

01local debounce = false
02 
03local UserInputService = game:GetService("UserInputService")
04    local Player = game.Players.LocalPlayer
05    local Character = Player.Character
06    local Humanoid = Character:WaitForChild("Humanoid")
07    UserInputService.InputBegan:Connect(function(InputObject)
08        if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
09    debounce = true
10local numberofanims = 3
11local num = math.random(1,numberofanims)
12    if num == 1 then
13                local Animation = Instance.new("Animation")
14                Animation.AnimationId = "rbxassetid://wasdwasdwasd"
15                local Track = Humanoid:LoadAnimation(Animation)
View all 32 lines...

The problem is, the debounce has no effect. The player can still spam click their mouse and the animations are cut off. Please tell me what I did wrong.

1 answer

Log in to vote
0
Answered by
bum5Br 97
5 years ago

You have a debounce but the if statement isn't checking if the debounce is true or not, so the code just runs. I didn't test this, so i have no idea if it works

01debounce = false
02 
03local UserInputService = game:GetService("UserInputService")
04    local Player = game.Players.LocalPlayer
05    local Character = Player.Character
06    local Humanoid = Character:WaitForChild("Humanoid")
07    UserInputService.InputBegan:Connect(function(InputObject)
08        if InputObject.UserInputType == Enum.UserInputType.MouseButton1 and not debounce then
09    debounce = true
10local numberofanims = 3
11local num = math.random(1,numberofanims)
12    if num == 1 then
13                local Animation = Instance.new("Animation")
14                Animation.AnimationId = "rbxassetid://wasdwasdwasd"
15                local Track = Humanoid:LoadAnimation(Animation)
View all 35 lines...
0
Just what I needed, thanks! Lyphios 77 — 5y
Ad

Answer this question