Answered by
4 years ago Edited 4 years ago
Hello.
You must make a debounce by adding a debounce as a variable.
Next, add an if statement checking if debounce == false
.
If it is, then the debounce will be equal to true.
Finally, you add a wait() (I used 1.5 seconds) and then set the debounce back to false.
Code:
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 | local Player = game.Players.LocalPlayer |
04 | local Character = workspace:WaitForChild(Player.Name) |
05 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
08 | local CombatEnabled = false |
10 | local CombatAnim = script:WaitForChild( "CombatAnim" ) |
16 | UserInputService.InputBegan:Connect( function (Input,IsTyping) |
18 | if Input.KeyCode = = Enum.KeyCode.E and not debounce then |
21 | print ( "Combat Enabled!" ) |
24 | while CombatEnabled = = true do |
25 | local randomAnimation = math.random( 1 , #animTable) |
26 | local randomAnim_Value = animTable [ randomAnimation ] |
27 | CombatAnim.AnimationId = tostring (randomAnim_Value) |
28 | local CombatAnimLoader = Humanoid:LoadAnimation(CombatAnim) |
32 | CombatAnimLoader:Play() |
33 | print (randomAnim_Value) |
34 | wait(CombatAnimLoader.Length + 0.2 ) |
37 | if CombatEnabled = = false then |
38 | print ( "Combat Disabled!" ) |
51 | UserInputService.InputEnded:Connect( function (Input, IsTyping) |
53 | if Input.KeyCode = = Enum.KeyCode.E then |