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

How to stop a script from damaging the Humanoid when spamming E?

Asked by 5 years ago
Edited 5 years ago

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 //--
02local UserInputService = game:GetService("UserInputService")
03local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
04local swing = Enum.KeyCode.E
05local spin = Enum.KeyCode.Q
06local damage = 0
07 
08--\\ SWING //--
09 
10function 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
View all 23 lines...

Any help?

1 answer

Log in to vote
0
Answered by 5 years ago

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 //--
02local UserInputService = game:GetService("UserInputService")
03local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
04local swing = Enum.KeyCode.E
05local spin = Enum.KeyCode.Q
06local damage = 0
07local debounce = false
08 
09--\\ SWING //--
10function 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)
View all 27 lines...

If you want to read about debounces and when to use them, check out this article. https://developer.roblox.com/en-us/articles/Debounce

0
I've tried it but it still doesn't stop it from attacking when spamming E. Thanks for the effort tho! ANormalPlayer_Alex 11 — 5y
Ad

Answer this question