Mryeetmemes

SwordScript

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