Advertisement
TheTomatooo

HitService (Module Script)

Sep 13th, 2023
7,118
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | Source Code | 1 0
  1. local module = {}
  2.  
  3. local debris = game:GetService("Debris")
  4.  
  5. local ss = game:GetService("ServerStorage")
  6. local modules = ss:WaitForChild("Modules")
  7. local stunHandler = require(modules:WaitForChild("StunHandlerV2"))
  8. local ragdollModule = require(modules:WaitForChild("Ragdoll"):WaitForChild("ModuleScript"))
  9.  
  10. function module.Hit(enemyHumanoid,damage,stunDuration,knockback,ragdoll,ragdollDuration)
  11.     local enemyHumRp = enemyHumanoid.Parent.HumanoidRootPart
  12.     if damage then
  13.         enemyHumanoid:TakeDamage(damage)
  14.     end
  15.    
  16.     if stunDuration then
  17.         enemyHumanoid.WalkSpeed = 16
  18.         enemyHumanoid.JumpPower = 50
  19.         stunHandler.Stun(enemyHumanoid,stunDuration)
  20.     end
  21.    
  22.     if ragdoll then
  23.         local ragdollTrigger = enemyHumanoid.Parent:FindFirstChild("RagdollTrigger")
  24.         if ragdollTrigger then
  25.             if not ragdollTrigger.Value then
  26.                 ragdollTrigger.Value = true
  27.                
  28.                 task.delay(ragdollDuration,function()
  29.                     if enemyHumanoid.Health > 0 then
  30.                         ragdollTrigger.Value = false
  31.                     end
  32.                 end)
  33.             end
  34.         end
  35.     end
  36.    
  37.     if knockback then
  38.         local bv = Instance.new("BodyVelocity")
  39.         bv.MaxForce = Vector3.new(math.huge,0,math.huge)
  40.         bv.P = 50000
  41.         bv.Velocity = knockback
  42.         bv.Parent = enemyHumRp
  43.        
  44.         debris:AddItem(bv,0.2)
  45.     end
  46.    
  47. end
  48.  
  49. return module
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement