How do I make TD piercing damage?

So I have this TD attack script all ready to go, I just need to add pierce. The thing is that I don’t know how to. I’ve tried doing it myself, but it didn’t work out, It kinda just did splash.

function tower.Attack(newTower, player)
	local config = newTower.Config
	local target = tower.FindTarget(newTower, config.Range.Value, config.TargetMode.Value)
	
	if target ~= nil and target:FindFirstChild("Humanoid") then
		
		AnimateEvent:FireAllClients(newTower, "Attack", target)
		if target then
			local targetCFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
			
			newTower.HumanoidRootPart.BodyGyro.CFrame = targetCFrame
		end
		
		abilities(newTower, config, target, player, config.TargetMode.Value)
		
		damage(target, config)
		
		task.wait(config.Cooldown.Value)
	end

	task.wait(0.05)

	if newTower and newTower.Parent then
		tower.Attack(newTower, player)
	end
end

well, pierce damage just ignores all armor (unless you have a different system). So you just subtract their HP, by exact amount of pierce damage being dealt.

sorry, I should’ve specified WHAT type of piercing. By this piercing I mean piercing through enemies.

You could make it delete the projectile after hitting a certain number enemies.
If it’s raycast, do a ray to nearest enemy but ignore the detection and find the 3 closest enemies that are hit by the ray.

well, it isnt a raycast, its a targeting system.

How does your current projectile system work rn

It targets a certain target based on its targeting setting. First, Last, Closest, Farthest etc. heres the function,

function tower.FindTarget(newTower, range, mode)
	local bestTarget = nil
	local bestWaypoint = nil
	local bestHealth = nil
	local bestDistance = nil

	for i, mob in ipairs(workspace.Mobs:GetChildren()) do
		local distanceToMob = (mob.HumanoidRootPart.Position - newTower.HumanoidRootPart.Position).Magnitude
		local distanceToWaypoint = (mob.HumanoidRootPart.Position - map.Waypoints["wp"..mob:WaitForChild("movingTo").Value].Position).Magnitude

		if distanceToMob <= range then
			if mode == "Near" then
				range = distanceToMob
				bestTarget = mob
			elseif mode == "First" then
				if not bestWaypoint or mob:WaitForChild("movingTo").Value >= bestWaypoint then
					bestWaypoint = mob:WaitForChild("movingTo").Value

					if not bestDistance or distanceToWaypoint < bestDistance then
						bestDistance = distanceToWaypoint
						bestTarget = mob
					end
				end
			elseif mode == "Last" then
				if not bestWaypoint or mob.movingTo.Value <= bestWaypoint then
					if bestWaypoint then
						bestDistance = nil
					end
					bestWaypoint = mob.movingTo.Value

					if not bestDistance or distanceToWaypoint > bestDistance then
						bestDistance = distanceToWaypoint
						bestTarget = mob
					end
				end
			elseif mode == "Strongest" then
				if not bestHealth or mob.Humanoid.Health > bestHealth then
					bestHealth = mob.Humanoid.Health
					bestTarget = mob
				end
			elseif mode == "Weakest" then
				if not bestHealth or mob.Humanoid.Health < bestHealth then
					bestHealth = mob.Humanoid.Health
					bestTarget = mob
				end
			end
		end
	end

	return bestTarget
end

U could change the system to shoot a raycast from the fire gun part to the enemy, then gets all the parts it touched and if it exist a humanoid in the parent, takedamage or whatever system u are using.
i could make a script for that but i cant rn, im on phone.