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:
local debounce = false
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
UserInputService.InputBegan:Connect(function(InputObject)
if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
debounce = true
local numberofanims = 3
local num = math.random(1,numberofanims)
if num == 1 then
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://wasdwasdwasd"
local Track = Humanoid:LoadAnimation(Animation)
Track:Play()
wait (1)
elseif num == 2 then
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://wasdwasdwasd"
local Track = Humanoid:LoadAnimation(Animation)
Track:Play()
wait(1)
elseif num == 3 then
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://wasdwasdwasd"
local Track = Humanoid:LoadAnimation(Animation)
Track:Play()
wait(1)
end
end
end)
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 comment
Just what I needed, thanks!