KrYn0MoRe

mc sword script v2

Jan 12th, 2021 (edited)
972
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.26 KB | None | 0 0
  1. local plr = owner
  2. local char = plr.Character
  3. local hum = char:FindFirstChildOfClass("Humanoid")
  4. local torso = char:FindFirstChild("Torso") or char:FindFirstChild("HumanoidRootPart")
  5. local head = char:FindFirstChild("Head")
  6.  
  7. if hum.RigType ~= Enum.HumanoidRigType.R6 then warn("Must be R6 rig to run this script.") return end
  8.  
  9. local tool = Instance.new("Tool")
  10. local handle = Instance.new("Part")
  11. local SpecialMesh2 = Instance.new("SpecialMesh")
  12. tool.Name = "AlmightyToast's Sword"
  13. tool.Parent = plr.Backpack
  14. tool.TextureId = 'rbxassetid:/4911466046'
  15. handle.Name = "Handle"
  16. handle.Parent = tool
  17. handle.Size = Vector3.new(3.1400001, 0.195999995, 3.1400001)
  18. handle.BottomSurface = Enum.SurfaceType.Smooth
  19. handle.CanCollide = false
  20. handle.TopSurface = Enum.SurfaceType.Smooth
  21. SpecialMesh2.Parent = handle
  22. SpecialMesh2.MeshId = "rbxassetid://3676810102"
  23. SpecialMesh2.Scale = Vector3.new(0.200000003, 0.200000003, 0.200000003)
  24. SpecialMesh2.TextureId = "rbxassetid://3676810220"
  25. SpecialMesh2.MeshType = Enum.MeshType.FileMesh
  26.  
  27. for i,v in pairs(tool:GetChildren()) do
  28.     if v:IsA("Part") then
  29.         v.Massless = true
  30.         v.Locked = true
  31.         v.Anchored = false
  32.         v.CanCollide = false
  33.         if v ~= handle then
  34.             local weld = Instance.new("Weld")
  35.             weld.Part0 = handle
  36.             weld.Part1 = v
  37.             weld.C0 = handle.CFrame:Inverse()
  38.             weld.C1 = v.CFrame:Inverse()
  39.             weld.Parent = v
  40.         else
  41.             v.CanCollide = true
  42.         end
  43.     end
  44. end
  45.  
  46. tool.Parent = char
  47.  
  48. local debris = game:GetService("Debris")
  49. local tween = game:GetService("TweenService")
  50.  
  51. local meta = {
  52.     tier = 1,
  53.     sharpness = -3,
  54.     knockback = 0,
  55. }
  56.  
  57. local using = false
  58. local equipped = false
  59. local holding = false
  60. local stamina = 100
  61. local dmg = 15 + (5 * meta.tier) + (5 * meta.sharpness)
  62. local kb = 25 + (5 * meta.knockback)
  63. local block_reduce = 0.7
  64. local ls = nil
  65. local blocking = false
  66. local combat_18 = true
  67. local first_person = true
  68. local hurt_fx = false
  69. local can_w_tap = false
  70.  
  71. if combat_18 then
  72.     speed = 0
  73. else
  74.     speed = 0.12
  75. end
  76.  
  77. local grips = {
  78.     swing = CFrame.new(-1.12343681, 7.46069873e-14, 0.865265131, -2.96722469e-08, 0.678822041, -0.734302819, -1, -4.37113883e-08, 0, -3.20973932e-08, 0.734302819, 0.678822041),
  79.     block = CFrame.new(-0.825168073, -0.020077154, 1.00834012, -0.275093406, 0.960726619, -0.0364401713, -0.146487176, -0.0044247508, 0.989202619, 0.950192153, 0.277461171, 0.141951352),
  80.     hold = CFrame.new(-1.10684741, 4.97379915e-14, 0.99055028, -3.20973932e-08, 0.734302819, 0.6788221, -1, -4.37113883e-08, 0, 2.96722487e-08, -0.6788221, 0.734302819),
  81. }
  82.  
  83. tool.Grip = grips.hold
  84.  
  85. warn([[
  86. - Made by KrYn0MoRe
  87. - W-tap for extra knockback
  88. - Hold R-Click to block 70% damage
  89. - Hold Left Control makes you sprint
  90. ]])
  91.  
  92. hum.JumpPower = 30
  93.  
  94. local hscript = char:FindFirstChild("Health")
  95.  
  96. if hscript then
  97.     hscript:Destroy()
  98. end
  99.  
  100. local ttip = tool.Name
  101.  
  102. ttip = ttip .. '\n'
  103.  
  104. for enchant,lvl in pairs(meta) do
  105.     --if lvl ~= 0 then
  106.         ttip = ttip .. '\n'
  107.         ttip = ttip .. enchant .. ' ' .. lvl
  108.     --end
  109. end
  110.  
  111. ttip = ttip .. '\n'
  112. ttip = ttip .. '\n' .. 'When in main hand:'
  113. ttip = ttip .. '\n'
  114. ttip = ttip .. '\n' .. speed .. ' Attack Speed'
  115. ttip = ttip .. '\n' .. dmg .. ' Attack Damage'
  116.  
  117. print(ttip)
  118.  
  119. tool.ToolTip = ttip
  120.  
  121. local aid = 0
  122.  
  123. function add_aid()
  124.     aid = aid + 1
  125.     return aid
  126. end
  127.  
  128. function check_aid(cid)
  129.     if aid == cid then
  130.         return true
  131.     end
  132. end
  133.  
  134. local walkremote = Instance.new("RemoteEvent")
  135. walkremote.Parent = tool
  136.  
  137. walkremote.OnServerEvent:Connect(function(plr,mode,data)
  138.     if mode == 1 then
  139.         can_w_tap = data
  140.     end
  141. end)
  142.  
  143. NLS([[
  144. player = game:GetService("Players").LocalPlayer
  145. mouse = player:GetMouse()
  146. char = player.Character
  147. hum = char:FindFirstChildOfClass("Humanoid")
  148. local walkremote = script.Parent
  149.  
  150. local oldspeed = hum.WalkSpeed
  151. local eating = false
  152. local running = false
  153.  
  154. mouse.KeyDown:Connect(function(key)
  155.     if string.byte(key) == 50 then
  156.         running = true
  157.         if not eating then
  158.             hum.WalkSpeed = 24
  159.             walkremote:FireServer(1,true)
  160.         end
  161.     end
  162. end)
  163. mouse.KeyUp:Connect(function(key)
  164.     if string.byte(key) == 50 then
  165.         running = false
  166.         if not eating then
  167.             hum.WalkSpeed = oldspeed
  168.             walkremote:FireServer(1,false)
  169.         end
  170.     end
  171.     if key == 'w' and hum.WalkSpeed == 24 then
  172.         walkremote:FireServer(1,true)
  173.     end
  174. end)
  175. walkremote.OnClientEvent:Connect(function(mode,data)
  176.     if mode == 1 then
  177.         if data == true then
  178.             eating = true
  179.             hum.WalkSpeed = 10
  180.             if running then
  181.                 walkremote:FireServer(1,false)
  182.             end
  183.         elseif data == false then
  184.             eating = false
  185.             if running then
  186.                 hum.WalkSpeed = 24
  187.                 walkremote:FireServer(1,true)
  188.             elseif not running then
  189.                 hum.WalkSpeed = oldspeed
  190.                 walkremote:FireServer(2,false)
  191.                 walkremote:FireServer(1,false)
  192.             end
  193.         end
  194.     end
  195. end)
  196. ]],walkremote)
  197.  
  198. local effects = {}
  199.  
  200. function effects.sandbox(var,func)
  201.     local env = getfenv(func)
  202.     local newenv = setmetatable({},{
  203.         __index = function(self,k)
  204.             if k=="script" then
  205.                 return var
  206.             else
  207.                 return env[k]
  208.             end
  209.         end,
  210.     })
  211.     setfenv(func,newenv)
  212.     return func
  213. end
  214.  
  215. local hitsound2 = Instance.new("Sound")
  216. hitsound2.SoundId = 'rbxassetid://3362346832'
  217. hitsound2.Volume = 1.5
  218. hitsound2.Parent = handle
  219.  
  220. local critsound = Instance.new("Sound")
  221. critsound.SoundId = 'rbxassetid://4801410586'
  222. critsound.Volume = 1.5
  223. critsound.Parent = handle
  224.  
  225. function effects.effect(par,tarhum,weld,damage,targtorso,crit)
  226.     if not combat_18 then
  227.         local confirm = Instance.new("IntValue",par)
  228.         confirm.Name = plr.Name .. 'swordhit'
  229.         confirm.Parent = par
  230.         debris:AddItem(confirm,0.12)
  231.     end
  232.     tarhum:TakeDamage(damage)
  233.     if not hitsound2 then
  234.         hitsound2 = Instance.new("Sound")
  235.         hitsound2.SoundId = 'rbxassetid://3362346832'
  236.         hitsound2.Volume = 1.5
  237.         hitsound2.Parent = handle
  238.     end
  239.     if not critsound then
  240.         critsound = Instance.new("Sound")
  241.         critsound.SoundId = 'rbxassetid://4801410586'
  242.         critsound.Volume = 1.5
  243.         critsound.Parent = handle
  244.     end
  245.     if math.random(1,2) == 1 and crit then
  246.         critsound.SoundId = 'rbxassetid://4801410586'
  247.     elseif math.random(1,2) == 2 and crit then
  248.         critsound.SoundId = 'rbxassetid://4801410149'
  249.     elseif math.random(1,2) == 1 then
  250.         hitsound2.SoundId = 'rbxassetid://3362346832'
  251.     else
  252.         hitsound2.SoundId = 'rbxassetid://3362337129'
  253.     end
  254.     if crit then
  255.         critsound:Play()
  256.     else
  257.         hitsound2:Play()
  258.     end
  259.     --[[
  260.     spawn(function()
  261.         repeat wait() until not hitsound2.IsPlaying
  262.         hitsound2.Parent = nil
  263.     end)
  264.     ]]
  265.     spawn(function()
  266.         local _kb = kb
  267.         if can_w_tap then
  268.             can_w_tap = false
  269.             _kb = _kb*1.5
  270.         end
  271.         local dir = (targtorso.Position-torso.Position).Unit
  272.         local b = Instance.new("BodyVelocity")
  273.         b.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
  274.         b.Velocity = Vector3.new(0,9,0) + (dir*_kb*2.25)
  275.         targtorso.Velocity = targtorso.Velocity + Vector3.new(0,10,0) + (torso.CFrame.LookVector*_kb)
  276.         b.Parent = targtorso
  277.         debris:AddItem(b,0.1)
  278.     end)
  279.    
  280.     if hurt_fx then
  281.         for i,v in pairs(par:GetChildren()) do
  282.             if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" and not v:IsDescendantOf(char) and not v.Parent:IsA("Tool") and v.Name ~= "fallblock" then
  283.                 local weld = Instance.new("Weld")
  284.                 local part = v:Clone()
  285.                 part.CanCollide = false
  286.                 part.Massless = true
  287.                 part.Anchored = false
  288.                 for i,n in pairs(part:GetDescendants()) do
  289.                     if not n:IsA("SpecialMesh") then
  290.                         n:Destroy()
  291.                     end
  292.                     if n:IsA("SpecialMesh") then
  293.                         n.TextureId = ""
  294.                         n.Scale = n.Scale * 1.001
  295.                     end
  296.                 end
  297.                 weld.Part0 = part
  298.                 weld.Part1 = v
  299.                 weld.Parent = part
  300.                 part.BrickColor = BrickColor.new("Really red")
  301.                 part.Size = v.Size * 1.001
  302.                 part.Material = Enum.Material.SmoothPlastic
  303.                 part.CFrame = v.CFrame
  304.                 part.Parent = v.Parent
  305.                 part.Name = "hurtcolor"
  306.                 if 0.6 >= v.Transparency then
  307.                     part.Transparency = 0.6
  308.                 end
  309.                 if v.Transparency > 0.6 then
  310.                     part.Transparency = v.Transparency*1.5
  311.                 end
  312.                 part.CanCollide = false
  313.                 game:GetService("Debris"):AddItem(part,0.1)
  314.             end
  315.         end
  316.     end
  317. end
  318.  
  319. local stamina = 100
  320.  
  321. local function recharge()
  322.     if 100 > stamina then
  323.         stamina = stamina + 10
  324.     end
  325.     if stamina > 100 then
  326.         stamina = 100
  327.     end
  328. end
  329.  
  330. spawn(function()
  331.     while wait(0.06) do
  332.         wait(0.06)
  333.         recharge()
  334.     end
  335. end)
  336.  
  337. local isFalling = false
  338. hum.StateChanged:Connect(function(old,new)
  339.     if new == Enum.HumanoidStateType.Landed then
  340.         isFalling = false
  341.     elseif new == Enum.HumanoidStateType.Running then
  342.         isFalling = false
  343.     elseif new == Enum.HumanoidStateType.RunningNoPhysics then
  344.         isFalling = false
  345.     elseif new == Enum.HumanoidStateType.Jumping then
  346.         isFalling = true
  347.     elseif new == Enum.HumanoidStateType.FallingDown then
  348.         isFalling = true
  349.     elseif new == Enum.HumanoidStateType.Freefall then
  350.         isFalling = true
  351.     elseif new == Enum.HumanoidStateType.Climbing then
  352.         isFalling = false
  353.     end
  354. end)
  355.  
  356. local hitanimid = 0
  357.  
  358. local function hit(target,close)
  359.     local cid = add_aid()
  360.     spawn(function()
  361.         hitanimid = 1
  362.         if hitanimid == 1 and check_aid(cid) then else return end
  363.         tween:Create(tool,TweenInfo.new(0.12),{Grip = grips.swing}):Play()
  364.         hitanimid = 2
  365.         wait(0.08)
  366.         if hitanimid == 2 and check_aid(cid) then else return end
  367.         tween:Create(tool,TweenInfo.new(0.12),{Grip = grips.block}):Play()
  368.         hitanimid = 3
  369.         wait(0.04)
  370.         if hitanimid == 3 and check_aid(cid) then else return end
  371.         tween:Create(tool,TweenInfo.new(0.12),{Grip = grips.hold}):Play()
  372.     end)
  373.     if (combat_18 or (stamina > 30 and not combat_18)) and ((target and close) or not first_person) then else return end
  374.        
  375.     local temp_dmg = 0
  376.     local crit = false
  377.    
  378.     if combat_18 then
  379.         temp_dmg = dmg
  380.     else
  381.         if isFalling then
  382.             temp_dmg = (dmg*1.57142857)
  383.             crit = true
  384.         elseif stamina > 30 then
  385.             temp_dmg = dmg
  386.         end
  387.         stamina = 0
  388.     end
  389.    
  390.     local connection
  391.    
  392.     if not first_person then
  393.         connection = handle.Touched:Connect(function(obj)
  394.             local targchar,targtorso,targhum
  395.             pcall(function()
  396.                 targchar = obj.Parent
  397.             end)
  398.             pcall(function()
  399.                 targtorso = targchar:FindFirstChild("Torso") or targchar:FindFirstChild("HumanoidRootPart")
  400.             end)
  401.             pcall(function()
  402.                 targhum = targchar:FindFirstChildOfClass("Humanoid")
  403.             end)
  404.             if targchar and targchar ~= char and targtorso and targhum then
  405.                 if targhum ~= nil then
  406.                     if targhum.Parent then
  407.                         if not targhum.Parent:FindFirstChild(plr.Name .. "swordhit 32k") and obj.Parent:IsA("Model") and targhum.Health > 0 then
  408.                             effects.effect(targhum.Parent,targhum,targchar.PrimaryPart or targtorso,temp_dmg,targtorso,crit)
  409.                         end
  410.                     end
  411.                 end
  412.             end
  413.         end)
  414.     elseif first_person then
  415.         local targchar,targtorso,targhum
  416.         for i,v in pairs(workspace:GetChildren()) do
  417.             if target:IsDescendantOf(v) then
  418.                 targchar = v
  419.             end
  420.         end
  421.         --[[
  422.         pcall(function()
  423.             targchar = target.Parent
  424.         end)
  425.         ]]
  426.         pcall(function()
  427.             targtorso = targchar:FindFirstChild("Torso") or targchar:FindFirstChild("HumanoidRootPart")
  428.         end)
  429.         pcall(function()
  430.             targhum = targchar:FindFirstChildOfClass("Humanoid")
  431.         end)
  432.         if target and targchar and targchar ~= char and targtorso and targhum then
  433.             if targhum ~= nil then
  434.                 if targhum.Parent then
  435.                     if not targhum.Parent:FindFirstChild(plr.Name .. "swordhit 32k") and targchar:IsA("Model") and targhum.Health > 0 then
  436.                         effects.effect(targhum.Parent,targhum,targchar.PrimaryPart,temp_dmg,targtorso,crit)
  437.                     end
  438.                 end
  439.             end
  440.         end
  441.     end
  442.    
  443.     if not combat_18 then
  444.         wait(0.12)
  445.     end
  446.    
  447.     if connection then
  448.         spawn(function()
  449.             wait(0.1)
  450.             connection:Disconnect()
  451.         end)
  452.     end
  453. end
  454.  
  455. local function CheckIfAlive()
  456.     local alive = false;
  457.     if (plr and plr.Parent and char and char.Parent and hum and hum.Parent and hum.Health > 0 and torso and torso.Parent and head and head.Parent) then
  458.         alive = true;
  459.     end;
  460.     return alive;
  461. end;
  462.  
  463. tool.Equipped:Connect(function()
  464.     char = tool.Parent;
  465.     plr = game:GetService("Players"):GetPlayerFromCharacter(char);
  466.     hum = char:FindFirstChildOfClass("Humanoid");
  467.     torso = char:FindFirstChild("Torso") or char:FindFirstChild("HumanoidRootPart");
  468.     head = char:FindFirstChild("Head");
  469.     if not CheckIfAlive() then tool.Parent = nil return end;
  470.     equipped = true
  471. end)
  472.  
  473. tool.Unequipped:Connect(function()
  474.     if 0 >= hum.Health then
  475.         tool:Destroy()
  476.     end
  477.     tween:Create(tool,TweenInfo.new(0),{Grip = grips.hold}):Play()
  478.     blocking = false
  479.     equipped = false
  480. end)
  481.  
  482. local mouseremote = Instance.new("RemoteEvent")
  483. mouseremote.Parent = tool
  484.  
  485. NLS([[
  486. workspace.Camera.FieldOfView = 90
  487. local plr = game:GetService("Players").LocalPlayer
  488. local char = plr.Character
  489. local torso = char:FindFirstChild("Torso") or char:FindFirstChild("HumanoidRootPart")
  490. local hum = char:FindFirstChildOfClass("Humanoid")
  491. local mouse = plr:GetMouse()
  492. local remote = script.Parent
  493.  
  494. mouse.TargetFilter = char
  495. plr.CameraMode = Enum.CameraMode.LockFirstPerson
  496.  
  497. mouse.Button1Down:Connect(function()
  498.     local target = mouse.Target
  499.     local mag = nil
  500.     local close = false
  501.     if target and torso then
  502.         mag = (torso.Position - target.Position).magnitude
  503.     end
  504.     if mag and 9 >= mag then
  505.         close = true
  506.     end
  507.     remote:FireServer(1,target,close)
  508. end)
  509.  
  510. mouse.Button2Down:Connect(function()
  511.     remote:FireServer(2,true)
  512. end)
  513.  
  514. mouse.Button2Up:Connect(function()
  515.     remote:FireServer(2,false)
  516. end)
  517. ]],mouseremote)
  518.  
  519. local curhealth = hum.Health
  520.  
  521. hum.HealthChanged:Connect(function(newhealth)
  522.     if curhealth > newhealth and newhealth > 0 then
  523.         if blocking then
  524.             local dmg = curhealth-newhealth
  525.             local heal = dmg*block_reduce
  526.             curhealth = hum.Health + heal
  527.             hum.Health += heal
  528.         end
  529.     end
  530.     curhealth = hum.Health
  531. end)
  532.  
  533. mouseremote.OnServerEvent:Connect(function(plr,mode,data,data2)
  534.     if mode == 1 and equipped and not using and not blocking then
  535.         using = true
  536.         hit(data,data2)
  537.         using = false
  538.     end
  539.     if mode == 2 then
  540.         add_aid()
  541.         if data then
  542.             blocking = true
  543.             tween:Create(tool,TweenInfo.new(0),{Grip = grips.block}):Play()
  544.         elseif not data then
  545.             blocking = false
  546.             tween:Create(tool,TweenInfo.new(0),{Grip = grips.hold}):Play()
  547.         end
  548.     end
  549. end)
Add Comment
Please, Sign In to add comment