Advertisement
Guest User

OURS

a guest
Feb 17th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.22 KB | None | 0 0
  1. local RunService = game:GetService("RunService")
  2. local Debris = game:GetService("Debris")
  3. local Players = game:GetService("Players")
  4.  
  5. local Tool = script.Parent
  6. local Sword = Tool.Handle
  7.  
  8. local antiTK = true
  9. local idleDamage = 5
  10. local slashDamage = 10
  11. local lungeDamage = 35
  12.  
  13. local damage = idleDamage
  14.  
  15. local SlashSound = Sword:WaitForChild("SlashSound")
  16. local LungeSound = Sword:WaitForChild("LungeSound")
  17. local UnsheathSound = Sword:WaitForChild("UnsheathSound")
  18.  
  19. local humanoidParts = {
  20.     ["Head"] = true,
  21.     ["Left Arm"] = true,
  22.     ["Left Leg"] = true,
  23.     ["Right Arm"] = true,
  24.     ["Right Leg"] = true,
  25.     ["Torso"] = true,
  26. }
  27.  
  28. function swordUp()
  29.     Tool.GripForward, Tool.GripRight, Tool.GripUp = Vector3.new(-1, 0, -0), Vector3.new(0, 0, -1), Vector3.new(0, 1, -0)
  30. end
  31.  
  32. function swordOut()
  33.     Tool.GripForward, Tool.GripRight, Tool.GripUp = Vector3.new(0, 1, -0), Vector3.new(0, -0, -1), Vector3.new(1, -0, -0)
  34. end
  35.  
  36. function toolAnimation(name)
  37.     local anim = Instance.new("StringValue", Tool)
  38.     anim.Name = "toolanim"
  39.     anim.Value = name
  40. end
  41.  
  42. function slash()
  43.     damage = slashDamage
  44.     SlashSound:play()
  45.  
  46.     toolAnimation("Slash")
  47. end
  48.  
  49. function lunge()
  50.     damage = lungeDamage
  51.     LungeSound:play()
  52.     toolAnimation("Lunge")
  53.  
  54.     wait(.25)
  55.     swordOut()
  56.     wait(.75)
  57.     swordUp()
  58. end
  59.  
  60. Tool.Enabled = true
  61. local lastSwing = 0
  62.  
  63. Tool.Activated:connect(function()
  64.     if not Tool.Enabled then return end
  65.    
  66.     Tool.Enabled = false
  67.    
  68.     local cooldown = RunService.Stepped:wait()
  69.    
  70.     if (cooldown - lastSwing < .2) then
  71.         lunge()
  72.     else
  73.         slash()
  74.     end
  75.    
  76.     lastSwing = cooldown
  77.  
  78.     damage = idleDamage
  79.     Tool.Enabled = true
  80. end)
  81.  
  82. function isHumanoidPart(partThatWasHitWithSword)
  83.     return partThatWasHitWithSword.Parent and humanoidParts[partThatWasHitWithSword.Name]
  84. end
  85.  
  86. function canDamage(attackingPlayer, defendingPlayer)
  87.     return not antiTK or attackingPlayer.TeamColor ~= defendingPlayer.TeamColor
  88. end
  89.  
  90. function swordIsInHand(attackingCharacter)
  91.     local rightArm = attackingCharacter:FindFirstChild("Right Arm")
  92.     local rightGripJoint = rightArm and rightArm:FindFirstChild("RightGrip")
  93.  
  94.     return rightGripJoint and (rightGripJoint.Part0 == Sword or rightGripJoint.Part1 == Sword)
  95. end
  96.  
  97. function tagHumanoid(humanoid, player)
  98.     local creatorTag = Instance.new("ObjectValue", humanoid)
  99.     creatorTag.Value = player
  100.     creatorTag.Name = "creator"
  101.     Debris:AddItem(creatorTag, 1)
  102. end
  103.  
  104. Sword.Touched:Connect(function(hit)
  105.     if not isHumanoidPart(hit) then return end
  106.  
  107.     local attackingCharacter = Tool.Parent
  108.     local attackingPlayer = Players:playerFromCharacter(attackingCharacter)
  109.     local attackingHumanoid = attackingCharacter:FindFirstChild("Humanoid")
  110.  
  111.     local potentialDefendingCharacter = hit.Parent
  112.     local defendingHumanoid = potentialDefendingCharacter:FindFirstChild("Humanoid")
  113.     local defendingPlayer = Players:GetPlayerFromCharacter(potentialDefendingCharacter)
  114.  
  115.     if defendingHumanoid and attackingHumanoid and defendingHumanoid ~= attackingHumanoid then
  116.         -- Allow damage of NPCs
  117.         if not defendingPlayer or canDamage(attackingPlayer, defendingPlayer) then
  118.             tagHumanoid(defendingHumanoid, attackingPlayer)
  119.             defendingHumanoid:TakeDamage(damage)           
  120.         end
  121.     end
  122. end)
  123.  
  124. Tool.Equipped:Connect(function() UnsheathSound:play() end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement