Weapon that only damages Npcs/Monsters (Damages without swing)

I am working on a survival game and players cant kill each other I want them to work together to kill monsters to progress through the game it works fine but I just want the damage without swinging bug gone.
– My current code –

local active = false
local hitting = false

local swordDamage = 15

script.Parent.Sword.Touched:Connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") then
		local name = hit.Parent.Name
		if not game.Players:FindFirstChild(name) then
			if active == false and hitting == false then
			
				
				if hit.Parent:findFirstChild("ForceField") then
					if hit.Parent.ForceField.Visible == true then 			
			
						return
					end
				end
				
				hitting = true
				hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - swordDamage
				local sound = Instance.new("Sound",hit.Parent)
				sound.PlayOnRemove = true
				sound.SoundId = "rbxassetid://4935128724"
				sound.Volume = 1
				sound.TimePosition = 1
		
				sound:Destroy()
				wait(.5)
				hitting = false
			end
		end
	end
end)
1 Like

If you want the weapon to deal damage only when it is swung then you should check when the sword has been swung.

Put the .Touched code inside your swing code so that it only activates whenever the weapon has been swung.

1 Like

Inside of the anim code, or this one?

btw how much u charge for boss fights? I need one for my game.

I’d recommend using Raycasting and then check the magnitude between the player and the monster, this is because .Touched event might not always fire correctly.