Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make better hitboxes?

Im trying to inflict damage on a dummy with a punching script I made. In this script I used a part that appears and disappears each time the mouse is clicked, it inflicts damage but not all the time. This is the only hitbox method I know so please help me.

This is what it looks like: Punches

The grey part is my hit box and the dummy should take damage each time it touches it.

And this is a part of the script I'm using:

local debounce = false

local	Box = Instance.new("Part")

local 	boxweld = Instance.new('Weld')
		boxweld.Name = "CWelds"
		boxweld.Part0 = Player.Character.Torso
		boxweld.Part1 = Box
		boxweld.Parent = Player.Character.Torso
		boxweld.C0 = CFrame.new(0, -1, -2)*CFrame.Angles(0, 0, 0)
		
		Box.Size = Vector3.new(4, 5, 4)
		Box.CanCollide = false
		Box.Anchored = false
		Box.Transparency = 0.5
		Box.Name = "Box"
		Box.Parent = Player.Character

Box.Touched:connect(function(part)
    local h = part.Parent:FindFirstChild("Humanoid")
	if h and (not debounce) and (h.Parent ~= Player.Character) then
       debounce = true
		 h:TakeDamage(math.random(10, 14)) 
		Box:Destroy()
	
end
end)

This isnt all of the script however it is where the problem is, if you need the whole script please tell me.

1 answer

✓ Accepted answer

Raycasting

Have you considered instead checking if the Player is facing the target and if they can hit the target?
A lot of games out there use this method instead of checking the mesh because putting a hitbox on the weapon and checking for an intersection can be inconvenient in certain games where this checking is not reliable or necessary (More overhead than raycasting, provided their masking is right).

Send a ray from the torso, in the direction of the torso, for about 2.5 studs, check if it hits a character and then damage the character it hit. Make sure you set the mask to ignore the Player's character.

2 comments

0

Thanks, I'll leave this open for a little bit longer to see if there are any other suggestions but if not I'll accept your answer.

0

The alternative is to simply check if the arm collides with the player using Touched. I wouldn't trust it for this case, and I'd rely on a raycast if I were you. Even more important to rely on a raycast if you're using networked combat, which you are.

This discussion is preserved as it was. New answers, comments, and votes are closed.