Advertisement
koreanhackerman

Linked Sword Roblox Script

Nov 30th, 2019
6,335
1
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.50 KB | None | 1 0
  1. r = game:service("RunService")
  2.  
  3. local damage = 0
  4.  
  5. sword = script.Parent.blade
  6. Tool = script.Parent
  7.  
  8. local damages,values,sounds = {30,45,65},{Tool.PlaySlash,Tool.PlayThrust,Tool.PlayOverhead},{Tool.Handle.SlashSound,Tool.Handle.OverheadSound,Tool.Handle.LungeSound}
  9. local enabledToDamage = true
  10.  
  11. function blow(hit)
  12.     if enabledToDamage == false then return end
  13.     enabledToDamage = false
  14.     if (hit.Parent == nil) then enabledToDamage = true return end -- happens when bullet hits sword
  15.     local humanoid = hit.Parent:findFirstChild("Humanoid")
  16.     local vCharacter = Tool.Parent
  17.     local vPlayer = game.Players:playerFromCharacter(vCharacter)
  18.     local hum = vCharacter:findFirstChild("Humanoid") -- non-nil if tool held by a character
  19.     if humanoid~=nil and humanoid ~= hum and hum ~= nil then
  20.         -- final check, make sure sword is in-hand
  21.         local right_arm = vCharacter:FindFirstChild("Right Arm")
  22.         if (right_arm ~= nil) then
  23.             local joint = right_arm:FindFirstChild("RightGrip")
  24.             if (joint ~= nil and (joint.Part0 == sword or joint.Part1 == sword)) then
  25.                 tagHumanoid(humanoid, vPlayer)
  26.                 humanoid:TakeDamage(damage)
  27.                 wait(1)
  28.                 untagHumanoid(humanoid)
  29.             else
  30.                 enabledToDamage = true
  31.             end
  32.         else
  33.             enabledToDamage = true
  34.         end
  35.     else
  36.         enabledToDamage = true
  37.     end
  38. end
  39.  
  40.  
  41. function tagHumanoid(humanoid, player)
  42.     local creator_tag = Instance.new("ObjectValue")
  43.     creator_tag.Value = player
  44.     creator_tag.Name = "creator"
  45.     creator_tag.Parent = humanoid
  46. end
  47.  
  48. function untagHumanoid(humanoid)
  49.     if humanoid ~= nil then
  50.         local tag = humanoid:findFirstChild("creator")
  51.         if tag ~= nil then
  52.             tag.Parent = nil
  53.         end
  54.     end
  55. end
  56.  
  57.  
  58. function attack()
  59.     damage = slash_damage
  60.     script.Parent.Handle.SlashSound:Play()
  61.     script.Parent.PlaySlash.Value = not script.Parent.PlaySlash.Value
  62. end
  63.  
  64. function lunge()
  65.     damage = lunge_damage
  66.     script.Parent.Handle.LungeSound:Play()
  67.     script.Parent.PlayOverhead.Value = not script.Parent.PlayOverhead.Value
  68.     force = Instance.new("BodyVelocity")
  69.     force.velocity = Vector3.new(0,10,0) --Tool.Parent.Torso.CFrame.lookVector * 80
  70.     force.Parent = Tool.Parent.Torso
  71.     wait(.5)
  72.     force.Parent = nil
  73.     wait(.5)
  74.     damage = slash_damage
  75. end
  76.  
  77.  
  78. Tool.Enabled = true
  79. local last_attack = 0
  80. local status = 0
  81.  
  82. function onActivated()
  83.     if not Tool.Enabled then
  84.         return
  85.     end
  86.     Tool.Enabled = false
  87.     local character = Tool.Parent;
  88.     local humanoid = character.Humanoid
  89.     if humanoid == nil then
  90.         print("Humanoid not found")
  91.         return
  92.     end
  93.     t = r.Stepped:wait()
  94.     if (t - last_attack < 1.5) then
  95.         if status == 3 then
  96.             status = 0
  97.             damage = 0
  98.         else
  99.             status = status + 1
  100.             values[status].Value = not values[status].Value
  101.             damage = damages[status]
  102.             sounds[status]:Play()
  103.             enabledToDamage = true
  104.             wait(0.5)
  105.             enabledToDamage = false
  106.         end
  107.     else
  108.         status = 0
  109.         damage = 0
  110.     end
  111.     last_attack = t
  112.     Tool.Enabled = true
  113. end
  114.  
  115. function onEquipped()
  116.     wait(1/3)
  117.     Tool.Handle.UnsheathSound:Play()
  118. end
  119.  
  120. Tool.Equipped:connect(onEquipped)
  121. script.Parent.Activated:connect(onActivated)
  122. connection = sword.Touched:connect(blow)
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement