Advertisement
HowToRoblox

SwordHandler

May 16th, 2020
4,089
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. local tool = script.Parent
  2.  
  3. local idleAnim = script:WaitForChild("Idle")
  4. local idleAnimTrack
  5. local swingAnim = script:WaitForChild("Swing")
  6. local swingAnimTrack
  7.  
  8. local slashSound = script:WaitForChild("SlashSound")
  9. local sheathSound = script:WaitForChild("SheathSound")
  10. local hitSound = script:WaitForChild("HitSound")
  11.  
  12. local hitCharacters = {}
  13. local debounce = false
  14.  
  15. tool.Equipped:Connect(function()
  16.    
  17.     local humanoid = script.Parent.Parent.Humanoid
  18.     if not idleAnimTrack then idleAnimTrack = humanoid:LoadAnimation(idleAnim) end
  19.    
  20.     idleAnimTrack:Play()
  21.    
  22.     sheathSound:Play()
  23. end)
  24. tool.Unequipped:Connect(function()
  25.    
  26.     if idleAnimTrack then idleAnimTrack:Stop() end
  27.     if swingAnimTrack then swingAnimTrack:Stop() end
  28.    
  29.     sheathSound:Play()
  30. end)
  31. tool.Activated:Connect(function()
  32.    
  33.     if debounce then return end
  34.     debounce = true
  35.        
  36.     local humanoid = script.Parent.Parent.Humanoid
  37.     if not swingAnimTrack then swingAnimTrack = humanoid:LoadAnimation(swingAnim) end
  38.    
  39.     swingAnimTrack:Play()
  40.    
  41.     wait(0.5)  
  42.     slashSound:Play()
  43.    
  44.     wait(0.5)
  45.     debounce = false
  46. end)
  47. tool.Blade.Touched:Connect(function(touch)
  48.    
  49.     if hitCharacters[touch.Parent] or not debounce then return end
  50.     if touch.Parent:FindFirstChild("Humanoid") then
  51.        
  52.         if touch.Name == "Head" then
  53.             touch.Parent.Humanoid:TakeDamage(20)
  54.         else
  55.             touch.Parent.Humanoid:TakeDamage(10)
  56.         end
  57.         hitSound:Play()
  58.         hitCharacters[touch.Parent] = true
  59.         wait(1)
  60.         hitCharacters[touch.Parent] = nil
  61.     end
  62. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement