Advertisement
HowToRoblox

CombatServer

Jul 23rd, 2021
5,907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.75 KB | None | 0 0
  1. local sound = script:WaitForChild("PunchSound")
  2.  
  3.  
  4.  
  5. game.Players.PlayerAdded:Connect(function(plr)
  6.    
  7.     plr.CharacterAdded:Connect(function(char)
  8.        
  9.        
  10.         local humanoid = char:WaitForChild("Humanoid")
  11.         local hrp = char:WaitForChild("HumanoidRootPart")
  12.        
  13.        
  14.         local soundClone = sound:Clone()
  15.         soundClone.Parent = hrp
  16.        
  17.        
  18.         local hitChars = {}
  19.        
  20.        
  21.         game:GetService("RunService").Heartbeat:Connect(function()
  22.                
  23.            
  24.             local animations = humanoid:GetPlayingAnimationTracks()
  25.  
  26.             local attacking = false
  27.  
  28.  
  29.             for i, animation in pairs(animations) do
  30.  
  31.  
  32.                 for i, combatAnim in pairs(game.ReplicatedStorage:WaitForChild("CombatAnimations"):GetChildren()) do
  33.  
  34.                     if animation.Animation.AnimationId == combatAnim.AnimationId then
  35.  
  36.                         attacking = true
  37.                     end
  38.                 end
  39.             end
  40.            
  41.            
  42.            
  43.             if attacking then
  44.                
  45.                
  46.                 local ray = Ray.new(hrp.Position, hrp.CFrame.LookVector * 3)
  47.                
  48.                 local part, position = workspace:FindPartOnRay(ray, char)
  49.                
  50.                
  51.                 if part and part.Parent:FindFirstChild("Humanoid") and not hitChars[part.Parent] then
  52.                    
  53.                    
  54.                     hitChars[part.Parent] = true
  55.                    
  56.                    
  57.                     local damage = 10
  58.                    
  59.                     if part.Name == "Head" then
  60.                        
  61.                         damage = 30
  62.                     end
  63.                    
  64.                    
  65.                     local bv = Instance.new("BodyVelocity")
  66.                     bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  67.                    
  68.                     bv.Velocity = hrp.CFrame.LookVector * 50 + Vector3.new(0, 10, 0)
  69.                    
  70.                     bv.Parent = part.Parent.HumanoidRootPart
  71.                    
  72.                    
  73.                     game:GetService("Debris"):AddItem(bv, 0.1)
  74.                    
  75.                    
  76.                     part.Parent.Humanoid:TakeDamage(damage)
  77.                    
  78.                     soundClone:Play()
  79.                    
  80.                    
  81.                     wait(0.6)
  82.                    
  83.                     hitChars[part.Parent] = nil
  84.                 end
  85.             end
  86.         end)
  87.     end)
  88. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement