Advertisement
dv3v

Local script

Oct 18th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.23 KB | None | 0 0
  1. --------------------
  2. -------------------- Variables
  3.  
  4. local players = game.Players
  5. local player = players.LocalPlayer
  6. local tool = script.Parent.Parent
  7. local character = player.Character or player.CharacterAdded:Wait()
  8. local human = character:WaitForChild("Humanoid")
  9. local mouse = player:GetMouse()
  10. local remoteEvent = tool:WaitForChild("remote_event")
  11.  
  12. local blocking = false
  13. local equipped = false
  14. local attacking = false
  15. local CurrentAttackAnimation = 0
  16. local HitCoolDown = false
  17.  
  18. --------------------
  19. -------------------- Load Animations
  20.  
  21. function loadAnims()
  22.     local success, result = pcall(function()
  23.         wait(.5)
  24.        
  25.         anim_idle = human:LoadAnimation(tool.Animations.idle)
  26.         anim_idle.Looped = true
  27.        
  28.         anim_attack_1 = human:LoadAnimation(tool.Animations.attack_1)
  29.         anim_attack_1.Looped = false
  30.        
  31.         anim_attack_2 =  human:LoadAnimation(tool.Animations.attack_2)
  32.         anim_attack_2.Looped = false
  33.        
  34.         anim_block_1 = human:LoadAnimation(tool.Animations.block_1)
  35.         anim_block_1.Looped = true
  36.        
  37.         anim_block_2 = human:LoadAnimation(tool.Animations.block_2)
  38.         anim_block_2.Looped = true
  39.        
  40.     end)
  41.    
  42.     if success == false then
  43.         character = player.Character or player.CharacterAdded:Wait()
  44.         human = character:WaitForChild("Humanoid")
  45.         loadAnims()
  46.     end
  47. end
  48. loadAnims()
  49.  
  50. --------------------
  51. -------------------- Arrays
  52.  
  53. local attack_Animations = {anim_attack_1, anim_attack_2}
  54. local block_Animations = {anim_block_1, anim_block_2}
  55.  
  56. --------------------
  57. -------------------- Functions
  58.  
  59. function PlayAnimation(animation, Time) --Remove any client-side looped animation glitches
  60.     animation:Play()
  61.     wait(Time)
  62.     animation:Stop()
  63. end
  64.  
  65. function PickAttackAnimation() --Cycle through attack animations
  66.     CurrentAttackAnimation = CurrentAttackAnimation + 1
  67.    
  68.     if CurrentAttackAnimation > #attack_Animations then
  69.         CurrentAttackAnimation = 1
  70.     end
  71.    
  72.     return attack_Animations[CurrentAttackAnimation]
  73. end
  74.  
  75. --------------------
  76. -------------------- Weapon Actions
  77.  
  78. tool.Equipped:Connect(function()
  79.     equipped = true
  80.     anim_idle:Play()
  81. end)
  82.  
  83. tool.Unequipped:Connect(function()
  84.     remoteEvent:FireServer("Block", false)
  85.     blocking = false
  86.     equipped = false
  87.     anim_idle:Stop()
  88. end)
  89.  
  90. tool.Activated:Connect(function()
  91.     if equipped == true and blocking == false and attacking == false then
  92.         remoteEvent:FireServer("Block", false)
  93.         attacking = true
  94.         PlayAnimation(PickAttackAnimation(), 1.25)
  95.         attacking = false
  96.     end
  97. end)
  98.  
  99. mouse.Button2Down:Connect(function()
  100.     if attacking == false and equipped == true then
  101.         blocking = true
  102.         remoteEvent:FireServer("Block", true)
  103.         spawn(function()
  104.             remoteEvent:FireServer("Stun", true)
  105.             wait(2)
  106.             remoteEvent:FireServer("Stun", false)
  107.         end)
  108.         CurrentBlockAnimation = block_Animations[math.random(1, #block_Animations)]
  109.         CurrentBlockAnimation:Play()
  110.     end
  111. end)
  112.  
  113. mouse.Button2Up:Connect(function()
  114.     blocking = false
  115.     remoteEvent:FireServer("Block", false)
  116.     CurrentBlockAnimation:Stop()
  117. end)
  118.  
  119. tool.blade.Touched:Connect(function(hit)
  120.     local humanoid = hit.Parent:FindFirstChild("Humanoid")
  121.     if humanoid and HitCoolDown == false and attacking == true then
  122.         HitCoolDown = true
  123.         remoteEvent:FireServer("Attack", humanoid)
  124.         wait(.5)
  125.         HitCoolDown = false
  126.     end
  127. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement