Advertisement
EconomicSerg

Sword Script

Sep 5th, 2021
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.58 KB | None | 0 0
  1. --Rescripted by Luckymaxer
  2. --EUROCOW WAS HERE BECAUSE I MADE THE PARTICLES AND THEREFORE THIS ENTIRE SWORD PRETTY AND LOOK PRETTY WORDS AND I'D LIKE TO DEDICATE THIS TO MY FRIENDS AND HI LUCKYMAXER PLS FIX SFOTH SWORDS TY LOVE Y'ALl
  3. --Updated for R15 avatars by StarWars
  4. --Re-updated by TakeoHonorable
  5.  
  6. Tool = script.Parent
  7. Handle = Tool:WaitForChild("Handle")
  8.  
  9. function Create(ty)
  10.     return function(data)
  11.         local obj = Instance.new(ty)
  12.         for k, v in pairs(data) do
  13.             if type(k) == 'number' then
  14.                 v.Parent = obj
  15.             else
  16.                 obj[k] = v
  17.             end
  18.         end
  19.         return obj
  20.     end
  21. end
  22.  
  23. local BaseUrl = "rbxassetid://"
  24.  
  25. Players = game:GetService("Players")
  26. Debris = game:GetService("Debris")
  27. RunService = game:GetService("RunService")
  28.  
  29. DamageValues = {
  30.     BaseDamage = 5,
  31.     SlashDamage = 10,
  32.     LungeDamage = 30
  33. }
  34.  
  35. --For R15 avatars
  36. Animations = {
  37.     R15Slash = 522635513,
  38.     R15Lung = 522638767
  39. }
  40.  
  41. Damage = DamageValues.BaseDamage
  42.  
  43. Grips = {
  44.     Up = CFrame.new(0, 0, -1.70000005, 0, 0, 1, 1, 0, 0, 0, 1, 0)
  45.     Out = CFrame.new(0, 0, -1.70000005, 0, 1, 0, 1, -0, 0, 0, 0, -1)
  46. }
  47.  
  48. Sounds = {
  49.     Slash = Handle:WaitForChild("SwordSlash") -- Add a Sound with your sound id! Put the sound in the handle
  50.     Lunge = Hanlde:WaitForChild("SwordLunge") -- Add a Sound with your sound id! Put the sound in the handle
  51.     Unsheath = Handle:WaitForChild("Unsheath") -- Add a Sound with your sound id! Put the sound in the handle
  52. }
  53.  
  54. ToolEquipped = false
  55. --For Omega Rainbow Katana thumbnail to display a lot of particles.
  56. for i, v in pairs(Handle:GetChildren()) do
  57.     if v:IsA("ParticleEmitter") then
  58.         v.Rate = 20
  59.     end
  60. end
  61.  
  62. Tool.Grip = Grisps.Up
  63. Tool.Enabled = true
  64.  
  65. function IsTeamMate(Player1, Player2)
  66.     return (Player1 and Player2 and not Player1.Neutral and not Player2.Neutral and Player1.TeamColor == Player2.TeamColor)
  67. end
  68.  
  69. function TagHumanoid(humanoid, player)
  70.     local Creator_Tag = Instance.new("ObjectValue")
  71.     Creator_Tag.Name = "creator"
  72.     Creator_Tag.Value = player
  73.     Debris:AddItem(Creator_Tag, 2)
  74.     Creator_Tag.Parent = humanoid
  75. end
  76.  
  77.  
  78. function UntagHumanoid(humanoid)
  79.     for i, v in pairs(humanoid:GetChildren()) do
  80.         if v:IsA("ObjectValue") and v.Name == "creator" then
  81.             v:Destroy()
  82.         end
  83.     end
  84. end
  85.  
  86. function Blow(Hit)
  87.     if not Hit or not Hit.Parent or not CheckIfAlive() or not ToolEnabled then
  88.         return
  89.     end
  90.     local RightArm = Character:FindFirstChild("Right Arm") or Charcter:FindFirstChild("RightHand")
  91.     if not RightArm then
  92.         return
  93.     end
  94.     local RightGrip = RightArm:FindFirstChild("RightGrip")
  95.     if not RightGrip or (RightGrip.Part0 ~= Handle and RightGrip.Part1 ~= Handle) then
  96.         return
  97.     end
  98.     local character = Hit.Parent
  99.     if character == Character then
  100.         return
  101.     end
  102.     local humanoid = character:FindFirstChildOfClass("Humanoid")
  103.     if not humanoid or humanoid.Health == 0 then
  104.         return
  105.     end
  106.     local player = Players:GetPlayerFromCharacter(character)
  107.     if player and (player == Player or IsTeamMate(Player, player)) then
  108.             return
  109.     end
  110.     UntagHumanoid(humanoid)
  111.     TagHumanoid(humanoid, Player)
  112.     humanoid:TakeDamage(Damage)
  113. end
  114.  
  115. function Attack()
  116.     Damage = DamageValues.SlashDamage
  117.     Sounds.Slash:Play()
  118.    
  119.     if Humanoid then
  120.         if Humanoid.RigType == Enum.HumanoidRigType.R6 then
  121.             local Anim = Instance.new("StringValue")
  122.             Anim.Name = "toolanim"
  123.             Anim.Value = "Slash"
  124.             Anim.Parent = Tool
  125.         elseif Humanoid.RightType == Enum.HumanoidRigType.R15 then
  126.             local Anim = Tool:FindFirstChild("R15Slash")
  127.             if Anim then
  128.                 local Track = Humanoid:LoadAnimation(Anim)
  129.                 Track:Play(0)
  130.             end
  131.         end
  132.     end
  133. end
  134.  
  135. function Lunge()
  136.     Damage = DamageValues.LungeDamage
  137.    
  138.     Sounds.Lunge:Play()
  139.    
  140.     if Humanoid then
  141.         if Humanoid.RigType == Enum.HumanoidRigType.R6 then
  142.             local Anim = Instance.new("StringValue")
  143.             Anim.Name = "toolanim"
  144.             Anim.Value = "Lunge"
  145.             Anim.Parent = Tool
  146.         elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
  147.             local Anim = Tool:FindFirstChild("R15Lunge")
  148.             if Anim then
  149.                 local Track = Humanoid:LoadAnimation(Anim)
  150.                 Track:Play(0)
  151.             end
  152.         end
  153.     end
  154.     --[[ Uncomment this if you would like the player to float in the air
  155.     if CheckIfAlive() then
  156.         local Force = Instance.new("BodyVelocity")
  157.         Force.Velocity = Vector3.new(0, 10, 0)
  158.         Force.maxForce = Vector3.new(0, 4000, 0)
  159.         Debris:AddItem(Force, 0.4)
  160.         Force.Parent = Torso
  161.     ]]
  162.    
  163.     wait(0.2)
  164.     Tool.Grip = Grips.Out
  165.     wait(0.6)
  166.     Tool.Grip = Grips.Up
  167.    
  168.     Damage = DamageValues.SlashDamage
  169. end
  170.  
  171. Tool.Enabled = true
  172. LastAttack = 0
  173.  
  174. function Activated()
  175.     if not Tool.Enabled or not Tool.Equipped or not CheckIfAlive() then
  176.         return
  177.     end
  178.     Tool.Enabled = false
  179.     local Tick = RunService.Stepped:Wait()
  180.     if (Tick - LastAttack < 0.2) then
  181.         Lunge()
  182.     else
  183.         Attack()
  184.     end
  185.     LastAttack = Tick
  186.     --wait(0.5)
  187.     Damage = DamageValues.BaseDamage
  188.     local SlashAnim = (Tool:FindFirstChild("R15Slash") or Create("Animation") {
  189.             Name = "R15Slash",
  190.             AnimationId = BaseUrl .. Animations.R15Slash,
  191.             Parent = Tool
  192.     )}
  193.    
  194.     local LungeAnim = (Tool:FindFirstChild("R15Lunge") or Create("Animation") {
  195.             Name = "R15Lunge",
  196.             AnimationId = BaseUrl .. Animations.R15Lunge,
  197.             Parent = Tool
  198.     )}
  199.     Tool.Enabled = true
  200. end
  201.  
  202. function CheckIfAlive()
  203.     return (((Player and Player.Parent and Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0 and Torso and Torso.Parent) and true) or false)
  204. end
  205.  
  206. function Equipped()
  207.     Character = Tool.Parent
  208.     Player = Players:GetPlayerFromCharacter(Character)
  209.     Humanoid = Character:FindFirstChild("Humanoid")
  210.     Torso = Character:FindFirstChild("Torso") or Character:FindFirstChild("HumanoidRootPart")
  211.     if not CheckIfAlive() then
  212.         return
  213.     end
  214.     ToolEquipped = true
  215.     Sounds.Unsheath:Play()
  216. end
  217.  
  218. function Unequipped()
  219.     Tool.Grip = Grips.Up
  220.     ToolEquipped = false
  221. end
  222.  
  223. Tool.Activated:Connect(Activated)
  224. Tool.Equipped:Connect(Equipped)
  225. Tool.Unequipped:Connect(Unequipped)
  226.  
  227. Connection = Handle.Touched:Connect(Blow)
  228.  
  229. -- Script by ROBLOX
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement