Aquarius_Raverus

my brain hurts

Apr 27th, 2020
1,298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.29 KB | None | 0 0
  1. -- Sword Server Script
  2. -- By Sylvern
  3. -- 4/19/2020
  4.  
  5. --[[
  6.    
  7.     Add animations when received.
  8.     Animations switch are Underhand and Overhand.
  9.    
  10. ]] --
  11.  
  12. local Player =
  13.     script:FindFirstAncestorWhichIsA("Player") or
  14.     game:GetService("Players"):GetPlayerFromCharacter(script.Parent.Parent)
  15. local Players = game:GetService("Players")
  16.  
  17. local Debris = game:GetService("Debris")
  18. local Storage = game:GetService("ReplicatedStorage")
  19.  
  20. local Tool = script.Parent
  21.  
  22. local Handle = Tool:WaitForChild("Handle")
  23.  
  24. local Animations = Tool:WaitForChild("Animations")
  25. local Particle = Storage:WaitForChild("ParticleEmitter")
  26.  
  27. local Configuration = Tool:WaitForChild("Configuration")
  28.  
  29. local Damage = Configuration:WaitForChild("Damage")
  30. local BlockDamage = Configuration:WaitForChild("BlockDamage")
  31.  
  32. local Event = script.Parent:WaitForChild("ChangeAnimation")
  33.  
  34. local Cooldown = 0.3
  35.  
  36. local RaycastHitBox = require(Tool:WaitForChild("RaycastHitbox"))
  37. local HitBox = RaycastHitBox:Initialize(Handle)
  38.  
  39. local Ev = Tool:WaitForChild("Weld")
  40.  
  41. local AnimationOn = "1" -- underhand
  42.  
  43. local Sounds = Tool:WaitForChild("Sounds")
  44. --
  45.  
  46. --[[
  47.     Animation 1 = Underhand
  48.     Animation 2 = Overhand
  49. ]] local OnCooldown = false
  50.  
  51. function playSound(sound)
  52.     sound:Play()
  53. end
  54.  
  55. HitBox.OnHit:Connect(
  56.     function(hit, humanoid)
  57.         if hit.Parent.Name == Player.Name then
  58.             return
  59.         end
  60.  
  61.         if hit.Parent.Humanoid then
  62.             local Facing = hit.Parent.HumanoidRootPart.CFrame.LookVector
  63.             local Vector = (Player.Character.HumanoidRootPart.Position - hit.Parent.HumanoidRootPart.Position).unit
  64.             local Angle = math.acos(Facing:Dot(Vector))
  65.             --        warn(Angle) -- 0.2 or 2
  66.  
  67.             if game.Players:FindFirstChild(hit.Parent.Name) then
  68.                 --        warn(hit.Parent.Name)
  69.  
  70.                 local playerPlr = game.Players:FindFirstChild(hit.Parent.Name)
  71.  
  72.                 if playerPlr.onBack.Value == true and Angle >= 2 and playerPlr.isBlocking.Value == 'No' or playerPlr.isBlocking.Value == 'None' then
  73.                     warn "Shield is on back. Cant attack."
  74.                    
  75.                     playSound(Sounds:WaitForChild('ShieldHit'))
  76.                     return
  77.                 end
  78.                
  79.  
  80.                 if playerPlr.isBlocking.Value == "Yes" and Angle >= 2 then
  81.                     humanoid:TakeDamage(Damage.Value)
  82.                     cloneBlood(hit.Parent.HumanoidRootPart)
  83.                     Knockback(hit.Parent.HumanoidRootPart, Player.Character.HumanoidRootPart)
  84.                     KnockForward(Player.Character.HumanoidRootPart)
  85.                     playSound(Sounds:WaitForChild("Hit"))
  86.  
  87.                     --        warn("what is minecraft...")
  88.                     return
  89.                 end
  90.  
  91.                 if playerPlr.isBlocking.Value == "Yes" and Angle <= 1 then
  92.                     --  humanoid:TakeDamage(BlockDamage.Value)
  93.                     --  cloneBlood(hit.Parent.HumanoidRootPart)
  94.                     playSound(Sounds:WaitForChild("ShieldHit"))
  95.                     reduceStamina(playerPlr)
  96.                     --                  Knockback(hit.Parent.HumanoidRootPart, Player.Character.HumanoidRootPart)
  97.                     --      KnockForward(Player.Character.HumanoidRootPart)
  98.  
  99.                     --             warn("what is my life")
  100.             --      stopHit(playerPlr)
  101.                     return
  102.                 end
  103.  
  104.                 if playerPlr.isBlocking.Value == "No" or "None"  then
  105.                     humanoid:TakeDamage(Damage.Value)
  106.                     cloneBlood(hit.Parent.HumanoidRootPart)
  107.                     Knockback(hit.Parent.HumanoidRootPart, Player.Character.HumanoidRootPart)
  108.  --                   KnockForward(Player.Character.HumanoidRootPart)
  109.                     playSound(Sounds:WaitForChild("Hit"))
  110.                     return
  111.                 end
  112.             else
  113.                 --      warn(hit.Parent.Name)
  114.  
  115.                 Slowness(hit.Parent.HumanoidRootPart)
  116.                 cloneBlood(hit.Parent.HumanoidRootPart)
  117.                 Knockback(hit.Parent.HumanoidRootPart, Player.Character.HumanoidRootPart)
  118.  
  119.      --           KnockForward(Player.Character.HumanoidRootPart)
  120.  
  121.                 hit.Parent.Humanoid:TakeDamage(Damage.Value)
  122.                 playSound(Sounds:WaitForChild("Hit"))
  123.                 return
  124.             end
  125.         end
  126.  
  127.         -- Add hit animation to player.
  128.     end
  129. )
  130.  
  131. function stopHit(plr)
  132.     plr:WaitForChild('CanHit').Value = false
  133.     wait(2)
  134.     plr:WaitForChild('CanHit').Value = true
  135. end
  136.  
  137.  
  138. function reduceStamina(plrModel)
  139.     local shieldStrength = plrModel:FindFirstChild("ShieldStrength")
  140.  
  141.     if shieldStrength then
  142.         shieldStrength.Value = shieldStrength.Value - 30
  143.     end
  144. end
  145.  
  146. function cloneBlood(plrModel)
  147.     local Clone = Particle:Clone()
  148.     Clone.Parent = plrModel
  149.     Debris:AddItem(Clone, 0.8)
  150. end
  151.  
  152. function Slowness(plrModel)
  153.     local BV = Instance.new("BodyVelocity", plrModel)
  154.     BV.Name = "Slowness"
  155.     BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  156.     BV.P = 2000
  157.     BV.Velocity = Vector3.new(0, 0, 0)
  158.     Debris:AddItem(BV, 0.2)
  159. end
  160.  
  161. function KnockForward(plrModel)
  162.     local BV = Instance.new("BodyVelocity", plrModel)
  163.     BV.Name = "Knockback"
  164.     BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  165.     BV.P = 2000
  166.     BV.Velocity = plrModel.CFrame.lookVector * 15
  167.     Debris:AddItem(BV, 0.2)
  168. end
  169.  
  170. function Knockback(plrModel, plrAttacking)
  171.     local BV = Instance.new("BodyVelocity", plrModel)
  172.     BV.Name = "Knockback"
  173.     BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  174.     --  BV.P = 2000
  175.     BV.Velocity = plrAttacking.CFrame.lookVector * 18
  176.     Debris:AddItem(BV, 0.2)
  177. end
  178.  
  179. function LoadAnimation(plrModel, animation)
  180.     local Animation = plrModel.Humanoid:LoadAnimation(animation)
  181.     Animation:Play()
  182. end
  183.  
  184. Tool.Activated:Connect(
  185.     function()
  186.         if OnCooldown then
  187.             return
  188.         end -- Debounce cooldown.
  189.  
  190.         if Player:WaitForChild('CanHit').Value == false then
  191.             return
  192.         end -- Can hit check.
  193.  
  194.         OnCooldown = true
  195.         LoadAnimation(game.Workspace[Player.Name], Animations[AnimationOn])
  196.         playSound(Sounds:WaitForChild("Swing"))
  197.         warn(AnimationOn)
  198.         HitBox:HitStart()
  199.         wait(0.8)
  200.         HitBox:HitStop()
  201.  
  202.         wait(Cooldown)
  203.         OnCooldown = false
  204.  
  205.         -- Play animation.
  206.     end
  207. )
  208.  
  209. Event.OnServerEvent:Connect(
  210.     function(plr) -- 1 is underhand and 2 is overhand
  211.         if AnimationOn == "1" then
  212.             AnimationOn = "2"
  213.             warn(AnimationOn)
  214.         elseif AnimationOn == "2" then
  215.             AnimationOn = "3"
  216.             warn(AnimationOn)
  217.         elseif AnimationOn == "3" then
  218.             AnimationOn = "1"
  219.             warn(AnimationOn)
  220.         end
  221.     end
  222. )
  223. Ev.OnServerEvent:Connect(
  224.     function(plr, action)
  225.         if action == "UnEquip" then
  226.             LoadAnimation(game.Workspace[plr.Name], Tool:WaitForChild("UnEquip"))
  227.             --  wait(0.5)
  228.             local char = plr.Character
  229.             local copy = Storage:WaitForChild("SwordCopy"):Clone()
  230.  
  231.             copy.Parent = char
  232.             copy.UpperTorso.Part1 = char.UpperTorso
  233.         end
  234.  
  235.         if action == "Equip" then
  236.             plr.Character:FindFirstChild("SwordCopy"):Destroy()
  237.             LoadAnimation(game.Workspace[plr.Name], Tool:WaitForChild("Equip"))
  238.         end
  239.     end
  240. )
Advertisement
Add Comment
Please, Sign In to add comment