Why is my punch function not running when the player's hand makes contact?

game.ReplicatedStorage.remotes.punch.OnServerEvent:Connect(function(player,damage)		
	local character = player.Character
	local Hand1 = character:WaitForChild("LeftHand")
	local Hand2 = character:WaitForChild("RightHand")
	print("punch activated")
	
	local function handTouched(hit)
		local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
		print("punch connected")
		if humanoid and humanoid.Parent ~= character then
			print("punch damage dealt")
			humanoid:TakeDamage(damage)
		end
		
		Hand1.Touched:Connect(handTouched)
		Hand2.Touched:Connect(handTouched)

	end
end)

Trying to utilize the .touched event to deal damage to a player once my punch animation has ran and they’ve began punching, but it seems like no matter what the code won’t even break past the second print that I’ve set up. print("punch connected").

The code runs without any errors, but when I get up close to a dummy that I’ve set up its health doesn’t decrease at all like it’s supposed to. This code that I’m using is a bit modified; found within the forums on here, so I’d assume that it would work. Not so sure why it’s not , anyone give me some direction on what I’ve done wrong?

Try to put Hand1.Touched:Connect(handTouched) and Hand2.Touched:Connect(handTouched) outside the HandTouched function.

game.ReplicatedStorage.remotes.punch.OnServerEvent:Connect(function(player,damage)		
	local character = player.Character
	local Hand1 = character:WaitForChild("LeftHand")
	local Hand2 = character:WaitForChild("RightHand")
	print("punch activated")
	
	local function handTouched(hit)
		local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
		print("punch connected")
		if humanoid and humanoid.Parent ~= character then
			print("punch damage dealt")
			humanoid:TakeDamage(damage)
		end
		
		

	end
   Hand1.Touched:Connect(handTouched)
   Hand2.Touched:Connect(handTouched)
end)
1 Like

I have already said this. :neutral_face:

well yeah but i wrote it for him like what if he didnt understand and needed help with fixing it instead of you saying the solution

Both of your answers were very clear. Thanks a bunch. I was pretty tired when I made this post, so I must’ve missed this simple solution. It works as it should now. :smile:

1 Like