Advertisement
TheTomatooo

CombatServer(Script)

Sep 13th, 2023
6,204
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.63 KB | Source Code | 1 0
  1. local rp = game:GetService("ReplicatedStorage")
  2. local remotes = rp:WaitForChild("Remotes")
  3. local animations = rp:WaitForChild("Animations")
  4.  
  5. local punchRemote = remotes:WaitForChild("Punch")
  6.  
  7. local debris = game:GetService("Debris")
  8. local ss = game:GetService("ServerStorage")
  9. local modules = ss:WaitForChild("Modules")
  10.  
  11. local TomatoHitbox = require(modules:WaitForChild("TomatoHitbox"))
  12. local hitService = require(modules:WaitForChild("HitService"))
  13.  
  14. local lastPunch = {}
  15.  
  16. local MAX_COMBO = 4
  17.  
  18. local function changeCombo(char)
  19.     local combo = char:GetAttribute("Combo")
  20.    
  21.     local player = game:GetService("Players"):GetPlayerFromCharacter(char)
  22.    
  23.     if lastPunch[player] then
  24.         local passedTime = os.clock() - lastPunch[player]
  25.         print(passedTime)
  26.         if passedTime <= 1 then
  27.             if combo >= MAX_COMBO then
  28.                 char:SetAttribute("Combo",1)
  29.             else
  30.                 char:SetAttribute("Combo",combo + 1)
  31.             end
  32.         else
  33.             char:SetAttribute("Combo",1)
  34.         end
  35.     else
  36.         if combo >= MAX_COMBO then
  37.             char:SetAttribute("Combo",1)
  38.         else
  39.             char:SetAttribute("Combo",combo + 1)
  40.         end
  41.     end
  42.    
  43.     lastPunch[player] = os.clock()
  44. end
  45.  
  46. local function getPunchAnim(char)
  47.     local combo = char:GetAttribute("Combo")
  48.     local punchAnims = animations:WaitForChild("Combat"):GetChildren()
  49.    
  50.     local currAnim = punchAnims[combo]
  51.    
  52.     return currAnim
  53. end
  54.  
  55. local function stopAnims(object)
  56.     for i,v in pairs(object:GetPlayingAnimationTracks()) do
  57.         v:Stop()
  58.     end
  59. end
  60.  
  61. punchRemote.OnServerEvent:Connect(function(player)
  62.     local char = player.Character
  63.     local hum = char:WaitForChild("Humanoid")
  64.     local humRp = char:WaitForChild("HumanoidRootPart")
  65.    
  66.     local attacking = char:GetAttribute("Attacking")
  67.     local punching = char:GetAttribute("Punch")
  68.     local stunned = char:GetAttribute("Stunned")
  69.    
  70.     if attacking or punching or stunned then return end
  71.    
  72.     char:SetAttribute("Attacking",true)
  73.     char:SetAttribute("Punch",true)
  74.    
  75.     changeCombo(char)
  76.     stopAnims(hum)
  77.    
  78.     hum.WalkSpeed = 10
  79.     hum.JumpPower = 0
  80.    
  81.     local ragdoll = false
  82.    
  83.     local newHitbox = TomatoHitbox.new()
  84.     newHitbox.Size = Vector3.new(6,6,6)
  85.     newHitbox.CFrame = humRp
  86.     newHitbox.Offset = CFrame.new(0,0,-2.5)
  87.    
  88.     newHitbox.onTouch = function(enemyHum)
  89.         if enemyHum ~= hum then
  90.             if enemyHum.Parent:GetAttribute("Ragdolled") or enemyHum.Health <= 0 then return end
  91.            
  92.             local enemyHumRp = enemyHum.Parent.HumanoidRootPart
  93.            
  94.             local center = (enemyHumRp.Position - humRp.Position).Unit
  95.             local strength = 10
  96.            
  97.             if char:GetAttribute("Combo") == MAX_COMBO then
  98.                 ragdoll = true
  99.                 strength = 35
  100.             end
  101.            
  102.             local knockback = center * strength
  103.            
  104.             hitService.Hit(enemyHum,2,1.25,knockback,ragdoll,2)
  105.            
  106.             if char:GetAttribute("Combo") ~= MAX_COMBO then
  107.                 local bv = Instance.new("BodyVelocity")
  108.                 bv.MaxForce = Vector3.new(math.huge,0,math.huge)
  109.                 bv.P = 50000
  110.                 bv.Velocity = knockback
  111.                 bv.Parent = humRp
  112.                
  113.                 debris:AddItem(bv,0.2)
  114.             end
  115.  
  116.            
  117.         end
  118.     end
  119.    
  120.     local playPunchAnim = hum:LoadAnimation(getPunchAnim(char))
  121.    
  122.     playPunchAnim.KeyframeReached:Connect(function(kf)
  123.         if kf == "Hit" then
  124.             char:SetAttribute("Attacking",false)
  125.            
  126.             task.spawn(function()
  127.                 if not char:GetAttribute("Stunned") then
  128.                     newHitbox:Start()
  129.                     task.wait(0.1)
  130.                     newHitbox:Stop()
  131.                     newHitbox:Destroy()
  132.                 else
  133.                     newHitbox:Stop()
  134.                     newHitbox:Destroy()
  135.                 end
  136.  
  137.             end)
  138.  
  139.            
  140.             if char:GetAttribute("Combo") == MAX_COMBO then
  141.                 task.wait(1)
  142.             end
  143.            
  144.             char:SetAttribute("Punch",false)
  145.            
  146.         end
  147.     end)
  148.    
  149.     playPunchAnim.Stopped:Connect(function()
  150.         hum.WalkSpeed = 16
  151.         hum.JumpPower = 50
  152.     end)
  153.    
  154.     playPunchAnim:Play()
  155.    
  156. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement