HowToRoblox

CombatHandler

Apr 24th, 2020
7,999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.51 KB | None | 0 0
  1. local leftPunch = script:WaitForChild("LPunch")
  2. local rightPunch = script:WaitForChild("RPunch")
  3.  
  4. local leftKick = script:WaitForChild("LKick")
  5. local rightKick = script:WaitForChild("RKick")
  6.  
  7.  
  8. local char = script.Parent
  9.  
  10. local humanoid = char:WaitForChild("Humanoid")
  11.  
  12.  
  13. local uis = game:GetService("UserInputService")
  14.  
  15.  
  16. local debounce = false
  17. local isAnimationPlaying = false
  18.  
  19.  
  20. local loadedAnimation
  21. local currentAnimationId
  22.  
  23.  
  24. local remoteEvent = game.ReplicatedStorage.OnSuccessfulHit
  25.  
  26.  
  27. uis.InputBegan:Connect(function(input, gameProcessed)
  28.    
  29.     if gameProcessed or isAnimationPlaying then return end
  30.  
  31.    
  32.     if input.KeyCode == Enum.KeyCode.Q then
  33.        
  34.        
  35.         isAnimationPlaying = true
  36.         currentAnimationId = leftPunch.AnimationId
  37.        
  38.         loadedAnimation = humanoid:LoadAnimation(leftPunch)
  39.        
  40.         loadedAnimation:Play()
  41.        
  42.        
  43.     elseif input.KeyCode == Enum.KeyCode.E then
  44.        
  45.        
  46.         isAnimationPlaying = true
  47.         currentAnimationId = rightPunch.AnimationId
  48.        
  49.         loadedAnimation = humanoid:LoadAnimation(rightPunch)
  50.        
  51.         loadedAnimation:Play()
  52.        
  53.        
  54.     elseif input.KeyCode == Enum.KeyCode.F then
  55.        
  56.        
  57.         isAnimationPlaying = true
  58.         currentAnimationId = leftKick.AnimationId
  59.        
  60.         loadedAnimation = humanoid:LoadAnimation(leftKick)
  61.        
  62.         loadedAnimation:Play()
  63.        
  64.        
  65.     elseif input.KeyCode == Enum.KeyCode.G then
  66.        
  67.        
  68.         isAnimationPlaying = true
  69.         currentAnimationId = rightKick.AnimationId
  70.        
  71.         loadedAnimation = humanoid:LoadAnimation(rightKick)
  72.        
  73.         loadedAnimation:Play()
  74.     end
  75.    
  76.     if loadedAnimation then
  77.        
  78.        
  79.         loadedAnimation.Stopped:Wait()
  80.        
  81.         isAnimationPlaying = false
  82.     end
  83. end)
  84.  
  85.  
  86. humanoid.Touched:Connect(function(hit, bodyPart)
  87.    
  88.     if not isAnimationPlaying or debounce then return end
  89.    
  90.     local charOfHitPlayer = hit.Parent
  91.     local humanoidOfHitPlayer = charOfHitPlayer:FindFirstChild("Humanoid")
  92.    
  93.     if not humanoidOfHitPlayer then return end
  94.    
  95.     debounce = true
  96.    
  97.    
  98.     if currentAnimationId == leftPunch.AnimationId and bodyPart.Name == "LeftHand" then
  99.        
  100.         remoteEvent:FireServer(humanoidOfHitPlayer)
  101.            
  102.     elseif currentAnimationId == rightPunch.AnimationId and bodyPart.Name == "RightHand" then
  103.        
  104.         remoteEvent:FireServer(humanoidOfHitPlayer)
  105.        
  106.     elseif currentAnimationId == leftKick.AnimationId and bodyPart.Name == "LeftFoot" then
  107.        
  108.         remoteEvent:FireServer(humanoidOfHitPlayer)
  109.        
  110.     elseif currentAnimationId == rightKick.AnimationId and bodyPart.Name == "RightFoot" then
  111.        
  112.         remoteEvent:FireServer(humanoidOfHitPlayer)
  113.     end
  114.    
  115.     wait(0.1)
  116.    
  117.     debounce = false
  118. end)
Add Comment
Please, Sign In to add comment