Touched not detecting an object its clearly in contact with

I have a touched event that triggers when a hitbox detects contact with a hurtbox.
However, it doesn’t happen consistenly for some reason.

Here’s the output (server)
image
These were taken when the player is in very close proximity to the opponent, so on paper, all of these hits should be detected
The script prints the player the hitbox belongs to and then prints the hurtbox it makes contact with.
The rest of the script doesn’t continue if it makes contact with the owner’s hurtbox, so there’s no need to worry about that
The hitbox fails when it doesn’t register the other player and doesnt print “hit player2”.

Script:

hitbox.Touched:Connect(function(touched)
	if hitActive then
		print(hitboxOwner.Name .. " " .. touched.Parent.Parent.Name)
		if touched.Parent.Parent ~= hitboxOwner then
			touched.Color = Color3.new(0.666667, 0, 0) --Changes color of hurtbox
			print("hit "..touched.Parent.Parent.Name)
			hitActive = false
			removeHitbox()
			hitboxOwner.Pause.Value = true
			touched.Parent.Parent.Pause.Value = true
			RCEvent:Fire(nil, 0.1) --Pauses animations
			wait(0.1)
			touched.Color = Color3.new(0.333333, 0.666667, 0) --Returns the color of hurtbox
			hitboxOwner.Pause.Value = false
			touched.Parent.Parent.Pause.Value = false
		end
	end
end)

What causes touched to be so inconsistent? Is there a way around it?

Try using a different method than Touched, that method is quite janky to work with. How about raycasting instead? :thinking:

2 Likes

How would I go about it? Can I still use the hitboxes shown from the video?

The boxes will be kept, but the raycasting should cast from the point you start hitting followed up by checking if the cast actually hits the hitbox.

It sounds like rays are a one dimensional thing
Is it possible for raycasting to cover a Vector3 space like the hitboxes?

It should possible, considering that raycasting is used in FPS games and sometimes melee-based games.