Punch system damaging people even though I didn't click the button to punch

The title is confusing, I know. I tried my best to explain it in one sentence.
I made a punch system. When you click it punches, although there is a slight problem I want to fix.

For some reason, my punch system is acting weird. Each time I click to punch, then touch someone with the arm I punched with, it will still damage them even though I punched them a while ago.
You can check the video below.

I don’t know how I could fix this or what the problem is in the script.

Damage portion of the script, this is all you need to know about the script, but if you want the full script then you can ask. I did this to keep the page clean

Normal script:

punchEvent.OnServerEvent:Connect(function(player, character)
	db = true
		if hit.Parent:FindFirstChild("Humanoid") then
			if hit.Parent.Name ~= character.Name then
				if db == true then
					db = false
					hit.Parent.Humanoid:TakeDamage(5 + statistics.Strength.Value)
					local damageSound = Instance.new("Sound", hit)
					damageSound.Name = "Hit"
					damageSound.SoundId = hitSound
					damageSound.PlaybackSpeed = playbackSpeed
					damageSound.RollOffMinDistance = 5
					damageSound.RollOffMaxDistance = 30
					damageSound.Volume = 0.25
					local impactAttachment = Instance.new("Attachment", character[attackingArm])
					impactAttachment.Position = Vector3.new(0, -1, 0)
					local impact = script.Parent.Impact:Clone()
					impact.Parent = impactAttachment

I hope to find a solution. I appreciate it greatly if you could help!

You should get the .touched function outside of the .OnServerEvent. Then make sure that when you start punching, a variable is enabled that allows the .touched function to fire. When the punch ends (Animation ends), then disable the variable.

1 Like

Thanks for the help!
Your solution helped greatly.

1 Like