Advertisement
Guest User

FightingSystem

a guest
Jul 21st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.30 KB | None | 0 0
  1. -- ServerScript "FightingSystem"
  2. script.WeaponEvents.Parent = game:GetService("ReplicatedStorage")
  3. script.SwingWeapon.Parent = game:GetService("StarterPlayer").StarterPlayerScripts
  4.  
  5. local CF = script.Armor
  6. game:GetService("Players").PlayerAdded:Connect(function(Player)
  7.     Player.CharacterAdded:Connect(function(Character)
  8.         WeldClothes(Character, CF.ShoulderPad)
  9.         WeldClothes(Character, CF.ShoulderPad, {BodyPart = "RightUpperArm"})
  10.         WeldClothes(Character, CF.ChestStrap)
  11.         WeldClothes(Character, CF.Glove)
  12.         WeldClothes(Character, CF.Glove, {BodyPart = "LeftHand", AngleOffset = Vector3.new(0, 180, 0)})
  13.         WeldClothes(Character, CF.Belt)
  14.         WeldClothes(Character, CF.Boot)
  15.         WeldClothes(Character, CF.Boot, {BodyPart = "LeftFoot"})
  16.         WeldClothes(Character, CF.UpperLegGuard)
  17.         WeldClothes(Character, CF.UpperLegGuard, {BodyPart = "RightUpperLeg", PositionOffset = Vector3.new(0.02, 0.03, -0.01)})
  18.         WeldClothes(Character, CF.LowerLegGuard)
  19.         WeldClothes(Character, CF.LowerLegGuard, {BodyPart = "RightLowerLeg", PositionOffset = Vector3.new(0.02, -0.07, -0.01)})
  20.         WeldClothes(Character, CF.ChestPlate)
  21.         WeldClothes(Character, CF.LowerArmGuard)
  22.         WeldClothes(Character, CF.LowerArmGuard, {BodyPart = "RightLowerArm", AngleOffset = Vector3.new(0, -90, 0), PositionOffset = Vector3.new(0.02, 0.06, 0)})
  23.         WeldClothes(Character, CF.Helmet)
  24.         WeldClothes(Character, CF.Staff) -- Change to CF.Sword for a sword instead of a staff.
  25.         WeldClothes(Character, CF.Shield)
  26.     end)
  27. end)
  28. function WeldClothes(Character, Clothes, CustomProperties)
  29.     if not Character then return end
  30.     if not Clothes then return end
  31.     if not Clothes:FindFirstChild("BodyPart") then return end
  32.     if not Clothes:FindFirstChild("PositionOffset") then return end
  33.     if not Clothes:FindFirstChild("AngleOffset") then return end
  34.     if not Character:FindFirstChild(Clothes.BodyPart.Value) then return end
  35.    
  36.     local Clothes = Clothes:Clone()
  37.     local Weld = Instance.new("Weld")
  38.     if CustomProperties then
  39.         if CustomProperties.BodyPart then
  40.             Clothes.BodyPart.Value = CustomProperties.BodyPart
  41.         end
  42.         if CustomProperties.PositionOffset then
  43.             Clothes.PositionOffset.Value = CustomProperties.PositionOffset
  44.         end
  45.         if CustomProperties.AngleOffset then
  46.             Clothes.AngleOffset.Value = CustomProperties.AngleOffset
  47.         end
  48.     end
  49.     Weld.Part0 = Character:WaitForChild(Clothes.BodyPart.Value)
  50.     Weld.Part1 = Clothes
  51.     Weld.C0 = CFrame.new(Clothes.PositionOffset.Value) * CFrame.Angles(math.rad(Clothes.AngleOffset.Value.X), math.rad(Clothes.AngleOffset.Value.Y), math.rad(Clothes.AngleOffset.Value.Z))
  52.     Weld.Parent = Clothes
  53.     Clothes.Parent = Character:FindFirstChild(Clothes.BodyPart.Value)
  54. end
  55.  
  56. local PlayerData = Instance.new("Folder")
  57. PlayerData.Name = "PlayerData"
  58. PlayerData.Parent = script
  59.  
  60. game:GetService("ReplicatedStorage").WeaponEvents.Swing.OnServerEvent:Connect(function(Player, Weapon, Time)
  61.     local Val = PlayerData:FindFirstChild(Player.Name)
  62.     if not Val then
  63.         Val = Instance.new("BoolValue")
  64.         Val.Name = Player.Name
  65.         Val.Parent = PlayerData
  66.     end
  67.     if Val.Value then
  68.         Val.Value = false
  69.         Player.Character.Humanoid.WalkSpeed = 16
  70.         game:GetService("ReplicatedStorage").WeaponEvents.Shield:FireClient(Player)
  71.     end
  72.    
  73.     local HitAlready = {}
  74.     local Hitting = Weapon:FindFirstChild("Blade").Touched:Connect(function(Hit)
  75.         if Hit.Parent:FindFirstChild("Humanoid") then
  76.             local AlreadyHit = false
  77.             for i, v in pairs(HitAlready) do
  78.                 if v == Hit.Parent then
  79.                     AlreadyHit = true
  80.                     break
  81.                 end
  82.             end
  83.             if not AlreadyHit then
  84.                 if Hit.Parent ~= Player.Character then
  85.                     local Attacker = Player.Character
  86.                     local Victim = Hit.Parent
  87.                     local Damage = Weapon.Damage.Value
  88.                     if PlayerData:FindFirstChild(Victim.Name) then
  89.                         if PlayerData:FindFirstChild(Victim.Name).Value then
  90.                             Damage = Damage * 0.1
  91.                         end
  92.                     end
  93.                     HitAlready[#HitAlready + 1] = Victim
  94.                     Victim.Humanoid.Health = Victim.Humanoid.Health - Damage
  95.                 end
  96.             end
  97.         end
  98.     end)
  99.     Weapon.Blade.Trail.Enabled = true
  100.     wait(Time)
  101.     Weapon.Blade.Trail.Enabled = false
  102.     Hitting:Disconnect()
  103. end)
  104. game:GetService("ReplicatedStorage").WeaponEvents.Shield.OnServerEvent:Connect(function(Player, Value)
  105.     local Val = PlayerData:FindFirstChild(Player.Name)
  106.     if not Val then
  107.         Val = Instance.new("BoolValue")
  108.         Val.Name = Player.Name
  109.         Val.Parent = PlayerData
  110.     end
  111.     Val.Value = Value
  112.     if Value then
  113.         Player.Character.Humanoid.WalkSpeed = 10
  114.     else
  115.         Player.Character.Humanoid.WalkSpeed = 16
  116.     end
  117. end)
  118.  
  119.  
  120.  
  121. -- LocalScript "SwingWeapon"
  122. local Player = game:GetService("Players").LocalPlayer
  123. local Mouse = Player:GetMouse()
  124.  
  125. local SwingEvent = game:GetService("ReplicatedStorage"):WaitForChild("WeaponEvents").Swing
  126. local ShieldEvent = game:GetService("ReplicatedStorage"):WaitForChild("WeaponEvents").Shield
  127.  
  128. local Time = 0.4
  129.  
  130. local ShieldTime = 0.5
  131.  
  132. local SlashOne = true
  133.  
  134. local Debounce = false
  135.  
  136. local SlashOneAnimation = "rbxassetid://03502981317"
  137. local SlashTwoAnimation = "rbxassetid://3503074713"
  138. local ShieldAnimation = "rbxassetid://3503279598"
  139.  
  140. Mouse.Button1Down:Connect(function()
  141.     if not Player.Character:FindFirstChild("HumanoidRootPart") then return end
  142.     if Debounce then return end
  143.     Debounce = true
  144.    
  145.     local Animation = Instance.new("Animation")
  146.     if SlashOne then
  147.         SlashOne = false
  148.         Animation.AnimationId = SlashOneAnimation
  149.     else
  150.         SlashOne = true
  151.         Animation.AnimationId = SlashTwoAnimation
  152.     end
  153.     local Weapon = Player.Character.RightHand:FindFirstChildOfClass("Part") or Player.Character.RightHand:FindFirstChildOfClass("UnionOperation")
  154.     SwingEvent:FireServer(Weapon, Time)
  155.     local Humanoid = Player.Character:FindFirstChild("Humanoid")
  156.     local Anim = Humanoid:LoadAnimation(Animation)
  157.     Anim:Play()
  158.     wait(Time)
  159.     Debounce = false
  160. end)
  161.  
  162. local Anim
  163.  
  164. Mouse.Button2Down:Connect(function()
  165.     ShieldEvent:FireServer(true)
  166.     local Humanoid = Player.Character:FindFirstChild("Humanoid")
  167.     local Animation = Instance.new("Animation")
  168.     Animation.AnimationId = ShieldAnimation
  169.     Anim = Humanoid:LoadAnimation(Animation)
  170.     Anim:Play()
  171.     wait(ShieldTime - (ShieldTime*0.01))
  172.     if Anim then
  173.         Anim:AdjustSpeed(0)
  174.     end
  175. end)
  176. Mouse.Button2Up:Connect(function()
  177.     ShieldEvent:FireServer(false)
  178.     if Anim then
  179.         Anim:Stop()
  180.     end
  181.     Anim = nil
  182. end)
  183.  
  184. ShieldEvent.OnClientEvent:Connect(function()
  185.     if Anim then
  186.         Anim:Stop()
  187.     end
  188.     Anim = nil
  189. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement