I guess I'll answer my own question now that I fixed it, just for the people who want to know.
I set a variable, (punchinprogress). This variable would act as the restraining order for the pressing of the key E.
01 | local player = game.Players.LocalPlayer |
02 | local char = player.Character or player.CharacterAdded:wait() |
03 | local Hum = char:WaitForChild( "Humanoid" ) |
04 | local animation = Instance.new( "Animation" ) |
05 | local punchinprogress = 0 |
09 | local animTrack = Hum:LoadAnimation(animation) |
11 | game:GetService( "UserInputService" ).InputBegan:connect( function (Key) |
13 | if Key.KeyCode = = Enum.KeyCode.E and punchinprogress = = 0 then |
15 | print ( "Punch Triggered" ) |
20 | print ( "Punch Accomplished" ) |
As you can see, E can only trigger the events followed if punchinprogress == 0. If punchinprogress == 1, then the function would be unable to continue on with its work.
If punchinprogress = 0, then it would immediately set punchinprogress to 1 to prevent further spamming. It then initiates the animation, waits for the animation to end, stops the animation, and sets punchinprogress to 0 so the process can be repeated.