Advertisement
Riley_Huntley

Untitled

Nov 25th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.38 KB | None | 0 0
  1. r = game:service("RunService")
  2.  
  3.  
  4. local damage = 15
  5.  
  6.  
  7. local slash_damage = 10
  8. local lunge_damage = 30
  9.  
  10. sword = script.Parent.Handle
  11. Tool = script.Parent
  12.  
  13.  
  14. local SlashSound = Instance.new("Sound")
  15. SlashSound.SoundId = "rbxasset://sounds\\swordslash.wav"
  16. SlashSound.Parent = sword
  17. SlashSound.Volume = .7
  18.  
  19. local LungeSound = Instance.new("Sound")
  20. LungeSound.SoundId = "rbxasset://sounds\\swordlunge.wav"
  21. LungeSound.Parent = sword
  22. LungeSound.Volume = .6
  23.  
  24. local UnsheathSound = Instance.new("Sound")
  25. UnsheathSound.SoundId = "rbxasset://sounds\\unsheath.wav"
  26. UnsheathSound.Parent = sword
  27. UnsheathSound.Volume = 1
  28.  
  29.  
  30. function blow(hit)
  31.     if (hit.Parent == nil) then return end -- happens when bullet hits sword
  32.  
  33.     local humanoid = hit.Parent:findFirstChild("Humanoid")
  34.     local vCharacter = Tool.Parent
  35.     local vPlayer = game.Players:playerFromCharacter(vCharacter)
  36.     local hum = vCharacter:findFirstChild("Humanoid") -- non-nil if tool held by a character
  37.     if humanoid~=nil and humanoid ~= hum and hum ~= nil then
  38.         -- final check, make sure sword is in-hand
  39.  
  40.         local right_arm = vCharacter:FindFirstChild("Right Arm")
  41.         if (right_arm ~= nil) then
  42.             local joint = right_arm:FindFirstChild("RightGrip")
  43.             if (joint ~= nil and (joint.Part0 == sword or joint.Part1 == sword)) then
  44.                 tagHumanoid(humanoid, vPlayer)
  45.                 humanoid:TakeDamage(damage)
  46.                 wait(1)
  47.                 untagHumanoid(humanoid)
  48.             end
  49.         end
  50.  
  51.  
  52.     end
  53. end
  54.  
  55.  
  56. function tagHumanoid(humanoid, player)
  57.     local creator_tag = Instance.new("ObjectValue")
  58.     creator_tag.Value = player
  59.     creator_tag.Name = "creator"
  60.     creator_tag.Parent = humanoid
  61. end
  62.  
  63. function untagHumanoid(humanoid)
  64.     if humanoid ~= nil then
  65.         local tag = humanoid:findFirstChild("creator")
  66.         if tag ~= nil then
  67.             tag.Parent = nil
  68.         end
  69.     end
  70. end
  71.  
  72.  
  73. function attack()
  74.     damage = slash_damage
  75.     SlashSound:play()
  76.     local anim = Instance.new("StringValue")
  77.     anim.Name = "toolanim"
  78.     anim.Value = "Slash"
  79.     anim.Parent = Tool
  80. end
  81.  
  82. function lunge()
  83.     damage = lunge_damage
  84.  
  85.     LungeSound:play()
  86.  
  87.     local anim = Instance.new("StringValue")
  88.     anim.Name = "toolanim"
  89.     anim.Value = "Lunge"
  90.     anim.Parent = Tool
  91.    
  92.    
  93.     force = Instance.new("BodyVelocity")
  94.     force.velocity = Vector3.new(0,10,0)
  95.    
  96.     force.maxForce = Vector3.new(0,4000,0) -- ADD THIS TO CHANGE MOMENTUM
  97.    
  98.     force.Parent = Tool.Parent.Torso
  99.     wait(.25)
  100.     swordOut()
  101.     wait(.25)
  102.     force.Parent = nil
  103.     wait(.5)
  104.     swordUp()
  105.  
  106.     damage = slash_damage
  107. end
  108.  
  109. function swordUp()
  110.     Tool.GripForward = Vector3.new(-1,0,0)
  111.     Tool.GripRight = Vector3.new(0,1,0)
  112.     Tool.GripUp = Vector3.new(0,0,1)
  113. end
  114.  
  115. function swordOut()
  116.     Tool.GripForward = Vector3.new(0,0,1)
  117.     Tool.GripRight = Vector3.new(0,-1,0)
  118.     Tool.GripUp = Vector3.new(-1,0,0)
  119. end
  120.  
  121. function swordAcross()
  122.     -- parry
  123. end
  124.  
  125.  
  126. Tool.Enabled = true
  127. local last_attack = 0
  128. function onActivated()
  129.  
  130.     if not Tool.Enabled then
  131.         return
  132.     end
  133.  
  134.     Tool.Enabled = false
  135.  
  136.     local character = Tool.Parent;
  137.     local humanoid = character.Humanoid
  138.     if humanoid == nil then
  139.         print("Humanoid not found")
  140.         return
  141.     end
  142.  
  143.     t = r.Stepped:wait()
  144.  
  145.     if (t - last_attack < .2) then
  146.         lunge()
  147.     else
  148.         attack()
  149.     end
  150.  
  151.     last_attack = t
  152.  
  153.     --wait(.5)
  154.  
  155.     Tool.Enabled = true
  156. end
  157.  
  158.  
  159. function onEquipped()
  160.     UnsheathSound:play()
  161. end
  162.  
  163.  
  164. script.Parent.Activated:connect(onActivated)
  165. script.Parent.Equipped:connect(onEquipped)
  166.  
  167.  
  168. connection = sword.Touched:connect(blow)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement