I don't know how to explain in such few words, but basically what my script does is that whenever the player presses E and a humanoid is touching the Handle of the tool, it damages him, the problem is that you can just spam E and damage the Humanoid alot while still in the attack animation, does anyone know how to fix it?
--\ The Script //--
01 | --\\ VARIABLES //-- |
02 | local UserInputService = game:GetService( "UserInputService" ) |
03 | local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait() |
04 | local swing = Enum.KeyCode.E |
05 | local spin = Enum.KeyCode.Q |
06 | local damage = 0 |
07 |
08 | --\\ SWING //-- |
09 |
10 | function swing(inputObject, gameProcessedEvent) |
11 | if inputObject.KeyCode = = Enum.KeyCode.E then |
12 | damage = 15 |
13 | script.Parent.Touched:Connect( function (part) |
14 | wait(. 7 ) |
15 | if part.Parent:WaitForChild( "Humanoid" ) then |
Any help?
So, what you need to do is add a debounce to your script. You seemingly did add a variable named debounce, but perhaps you forgot to actually code the debounce in? This code should be working:
01 | --\\ VARIABLES //-- |
02 | local UserInputService = game:GetService( "UserInputService" ) |
03 | local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait() |
04 | local swing = Enum.KeyCode.E |
05 | local spin = Enum.KeyCode.Q |
06 | local damage = 0 |
07 | local debounce = false |
08 |
09 | --\\ SWING //-- |
10 | function swing(inputObject, gameProcessedEvent) |
11 | if debounce = = false then |
12 | debounce = true |
13 | if inputObject.KeyCode = = Enum.KeyCode.E then |
14 | damage = 15 |
15 | script.Parent.Touched:Connect( function (part) |
If you want to read about debounces and when to use them, check out this article. https://developer.roblox.com/en-us/articles/Debounce