Advertisement
SxScripting

Tool Combat [Server]

Dec 20th, 2022
3,065
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. local Tool: Tool = script.Parent
  2. local Player = Tool.Parent.Parent
  3. local Char: Model = Player.Character or Player.CharacterAdded:Wait()
  4.  
  5. local Humanoid = Char:WaitForChild("Humanoid")
  6. local RunService = game:GetService("RunService")
  7. local Debris = game:GetService("Debris")
  8. local RS = game:GetService("ReplicatedStorage")
  9. local IsPunched = Char:WaitForChild("IsPunched");
  10.  
  11. local Combo: number = 0;
  12. local Debounce: boolean = nil;
  13. local changeDebounce: boolean = nil
  14. local Main: RBXScriptConnection = nil
  15.  
  16.  
  17. local DMG = 5; -- amount of dmg
  18. local extraDMG = 2 -- Extra dmg at the last m1
  19. local Gwait = .3 -- General Wait
  20. local Fwait = 3 -- Final Wait
  21. local resetWait = 1.2 --7 -- Wait Time until combo resets
  22.  
  23. local function findPlayerFixBox(): boolean -- Finds enemycharacter and increments 1 to combo when found, if not we reset everything to nil
  24. local Params = OverlapParams.new();
  25. Params.FilterDescendantsInstances = {Char, game.Workspace.Baseplate}
  26. Params.FilterType = Enum.RaycastFilterType.Blacklist
  27.  
  28. local InArea,EnemyCharacter,EnemyPlayer;
  29.  
  30. for Index,Value in pairs(game.Workspace:GetPartBoundsInBox(Char.HumanoidRootPart.CFrame * CFrame.new(0,0,-2.3),Vector3.new(5.5,5,5),Params)) do
  31. if Value.Parent:FindFirstChild("Humanoid") then
  32. InArea = true;
  33. EnemyCharacter = Value.Parent
  34. EnemyPlayer = game.Players:GetPlayerFromCharacter(EnemyCharacter)
  35.  
  36. return InArea, EnemyCharacter, EnemyPlayer
  37. else
  38. InArea = nil;
  39. EnemyCharacter = nil;
  40. EnemyPlayer = nil;
  41.  
  42. return InArea, EnemyCharacter, EnemyPlayer
  43. end
  44. end
  45. end
  46.  
  47. local function changeSpeed(Humanoid: Humanoid,WK: number, JP: number) -- Changes Speed of character
  48. Humanoid.WalkSpeed = WK;
  49. Humanoid.JumpPower = JP;
  50. end
  51.  
  52. local function ApplyParticle(InArea: boolean, EneChar: Model) -- Applys the Particle and Animation and Knockback
  53. if not InArea then return end
  54. if Combo == 5 then
  55. local EffectVelocity = Instance.new("BodyVelocity", EneChar:WaitForChild("HumanoidRootPart"))
  56. EffectVelocity.MaxForce = Vector3.new(1, 1, 1) * 1000000;
  57. EffectVelocity.Velocity = Vector3.new(1, 1, 1) * Char:WaitForChild("HumanoidRootPart").CFrame.LookVector * math.random(60, 120)
  58. Debris:AddItem(EffectVelocity, Gwait)
  59. end
  60.  
  61. local particEffect = game.ServerStorage.Effects.HitEffect.Attachment:Clone()
  62. particEffect.Parent = EneChar:WaitForChild("HumanoidRootPart")
  63. EneChar:WaitForChild("Humanoid"):LoadAnimation(RS.HitStun):Play()
  64.  
  65. Debris:AddItem(particEffect,Gwait + .1)
  66. end
  67.  
  68. --@Override TakeDamage Function()
  69. local function TakeDamage(InArea: boolean, EnemyCharacter: Model)
  70. if not InArea then return end
  71. if Combo == 5 then EnemyCharacter:WaitForChild("Humanoid"):TakeDamage(DMG + extraDMG); return end
  72. EnemyCharacter:WaitForChild("Humanoid"):TakeDamage(DMG)
  73. end
  74.  
  75.  
  76. local function comboCheck(InArea: boolean, EneChar: Model, EnePla: Player) -- Resets combo if they take too long too punch and plays animations.
  77. if Combo == 0 then return end
  78. if changeDebounce then return end
  79. changeDebounce = true
  80. changeSpeed(Char.Humanoid, 8, 25)
  81. if EneChar then
  82. EneChar:WaitForChild("IsPunched").Value = true;
  83. changeSpeed(EneChar.Humanoid, 4, 10)
  84. end
  85.  
  86. if Main then Main:Disconnect(); Main = nil end
  87. local Start = tick()
  88.  
  89. local mainAnim = {
  90. RS.Animations.Hit1;
  91. RS.Animations.Hit2;
  92. RS.Animations.Hit3;
  93. RS.Animations.Hit4;
  94. RS.Animations.Hit5
  95. }
  96. local Hit = Humanoid:LoadAnimation(mainAnim[Combo]):Play()
  97.  
  98. ApplyParticle(InArea,EneChar)
  99. TakeDamage(InArea,EneChar)
  100. if Combo == 5 then
  101. changeSpeed(Char.Humanoid,16,50)
  102.  
  103. if EneChar then
  104. task.wait(.3)
  105. EneChar:WaitForChild("IsPunched").Value = false;
  106. changeSpeed(EneChar.Humanoid, 16, 50)
  107. end
  108. task.wait(Fwait)
  109. Combo = 0;
  110. else
  111. task.wait(Gwait)
  112. end
  113.  
  114. Main = RunService.Heartbeat:Connect(function()
  115. if tick() - Start >= resetWait then
  116. Main:Disconnect()
  117. Main = nil
  118. Combo = 0;
  119.  
  120. if EneChar then EneChar:WaitForChild("IsPunched").Value = false end
  121. else
  122. if EneChar then EneChar:WaitForChild("IsPunched").Value = true end
  123. end
  124. end)
  125. changeSpeed(Char.Humanoid, 16, 50)
  126. if EneChar then
  127. changeSpeed(EneChar.Humanoid, 16, 50)
  128. end
  129. changeDebounce = nil
  130. end
  131.  
  132. --Char.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
  133. -- local InArea,EnemyCharacter = findPlayerFixBox();
  134. -- if not InArea then return end
  135. -- if Combo >= 4 then
  136. -- Char:WaitForChild("IsPunched").Value = false;
  137. -- end
  138.  
  139. --end)
  140.  
  141. Tool.Activated:Connect(function(Humano :Humanoid)
  142. if Char:WaitForChild("IsPunched").Value then return end
  143. if Debounce then return end
  144. Debounce = true
  145.  
  146. if not Combo then Combo = 0; end
  147. local InArea,EnemyCharacter = findPlayerFixBox();
  148. Combo += 1;
  149.  
  150. comboCheck(InArea, EnemyCharacter)
  151. Debounce = nil
  152. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement