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

How would i go about adding a debounce to this localscript?

Asked by
Dec_ade 47
4 years ago

How can i make a debounce for this script?

01local UserInputService = game:GetService("UserInputService")
02local Player = game.Players.LocalPlayer
03 
04local Character = workspace:WaitForChild(Player.Name)
05local Humanoid = Character:WaitForChild("Humanoid")
06 
07 
08local CombatEnabled = false
09 
10local CombatAnim = script:WaitForChild("CombatAnim")
11 
13 
14 
15 
View all 54 lines...

1 answer

Log in to vote
1
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:

01local UserInputService = game:GetService("UserInputService")
02local Player = game.Players.LocalPlayer
03 
04local Character = workspace:WaitForChild(Player.Name)
05local Humanoid = Character:WaitForChild("Humanoid")
06 
07 
08local CombatEnabled = false
09 
10local CombatAnim = script:WaitForChild("CombatAnim")
11 
13 
14local debounce = false
15 
View all 57 lines...
Ad

Answer this question