ttvmetroidd

punch service

Jun 20th, 2024
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. local repstorage = game:GetService("ReplicatedStorage")
  2.  
  3. local Events = repstorage.Events
  4.  
  5. local module = {}
  6. local punchDebounces = {}
  7.  
  8. Events.Punch.OnServerEvent:Connect(function(player)
  9. if punchDebounces[player] then
  10. return
  11. end
  12. local character = player.Character
  13. if character == nil then
  14. return
  15. end
  16. local humanoid = character:FindFirstChild("Humanoid")
  17. if humanoid == nil then
  18. return
  19. end
  20. if humanoid.Health == 0 then
  21. return
  22. end
  23. task.spawn(function()
  24. punchDebounces[player] = true
  25. task.wait(0.8)
  26. if punchDebounces[player] then
  27. punchDebounces[player] = nil
  28. end
  29. end)
  30. local boxCFrame = character.HumanoidRootPart.CFrame
  31. local boxSize = Vector3.new(5, 5, 5)
  32.  
  33. local params = OverlapParams.new()
  34. params.CollisionGroup = "Default"
  35. params.FilterDescendantsInstances = {character}
  36. params.FilterType = Enum.RaycastFilterType.Exclude
  37. params.MaxParts = 50
  38.  
  39. local objectInHitbox = workspace:GetPartBoundsInBox(boxCFrame, boxSize, params)
  40. task.wait(0.2)
  41. for _, v in objectInHitbox do
  42. local otherHumanoid = v.Parent:FindFirstChild("Humanoid")
  43. if otherHumanoid == nil then
  44. continue
  45. end
  46. if otherHumanoid.Health == 0 then
  47. return
  48. end
  49. local hitParticle = script.HitParticle:Clone()
  50. hitParticle.Parent = v.Parent.HumanoidRootPart
  51. hitParticle:Emit(10)
  52. otherHumanoid.Health -= 30
  53.  
  54. task.delay(3, function()
  55. if hitParticle == nil then
  56. return
  57. end
  58. if hitParticle.Parent == nil then
  59. return
  60. end
  61. hitParticle:Destroy()
  62. end)
  63. break
  64. end
  65. end)
  66.  
  67. return module
Advertisement
Add Comment
Please, Sign In to add comment