Help With Touch Function

So I want it where if i slash with a sword it would only damage the enemy once, however even when the player is not swinging the sword, it still damages the enemy.

touch = character.HumanoidRootPart.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") and CanAttack == true then
			local EHumanoid = hit.Parent:FindFirstChild("Humanoid")
			EHumanoid:TakeDamage(10)
            touch:Disconnect()
	end
end)

Put a Print statement in the function after the If statement that prints the value of CanAttack to see what the value is for troubleshooting purposes.
I’m guessing that somehow CanAttack is being set to true somewhere else in your scripts.

Oh yea, you are right, I have CanAttack set automatically to true.

1 Like

CanAttack needs to be set back to false after you make it true.