How to make a hit script?

For example, you punch a player and the hit animation play. The hitbox doesn’t affect you tho… How to make it? I only need a script for hit script, and not for the punch script.

1 Like

Are you asking how to make a punch hitbox?

There are multiple options to choose when making combat hitboxes. There are .Touched, WorldRoot:GetPartsInPart() and WorldRoot:Raycast().


.Touched

  • While .Touched still has uses, it is not advised to use this event for hitboxes. .Touched relies on physics-based collision which makes it inaccurate, and plus it is vulnerable to network ownership exploits. So you can tick this out of your list.

WorldRoot:GetPartsInPart()

  • Now you have two choices, WorldRoot:GetPartsInPart() or WorldRoot:Raycast(). These two are the best choices that you have when it comes to hitboxes. Now in Region3 (which was superceded by WorldRoot:GetPartsInPart()), it didn’t account for rotated objects. But WorldRoot:GetPartsInPart() does, so that is good. But sadly it is the most expensive out of the three choices.

WorldRoot:Raycast()

  • Raycasting or WorldRoot:Raycast() is the most accurate out of the three and is almost as performant as .Touched (slightly more expensive). WorldRoot:Raycast() does not rely on a physics-simulation like .Touched which makes it reliable, and it also gives you the exact position of the hit. Whenever using raycasting for hitboxes, I recommend using modules like ClientCast or RaycastHitbox.

TL;DR?

.Touched is unreliable and vulnerable to exploits, WorldRoot:GetPartsInPart() is okay but is costly when it comes to performance, and WorldRoot:Raycast() is the most reliable and accurate out of the 3 options.

2 Likes