Aquarius_Raverus

a

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