How do i make a "burst gun" tower in tower defense?

My ideal is: A cowboy tower, he shoot 6 times at the enemy then he will do a reload animation then he continue shoot at the enemy but i have no ideal how to do that here my code:

function tower.Attack(newTower, player)
	local config = newTower.Config
	local target = tower.FindTarget(newTower, config.Range.Value, config.TargetMode.Value)
	
	if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then

		local targetCFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
				
		newTower.HumanoidRootPart.BodyGyro.CFrame = targetCFrame
		
		animateTowerEvent:FireAllClients(newTower, "Attack", target)
		
		wait(config.AnimationDelay.Value)

		target.Humanoid:TakeDamage(config.Damage.Value)
		
	end
	
	task.wait(config.Cooldown.Value)
	
	if newTower and newTower.Parent then
		tower.Attack(newTower, player)
	end
end

i know how to make the tower damage the enemy 1 time then cooldown but i have no ideal how to make the tower deal damage multiple time then cooldown. Any suggestions?

could you say where exactly it does cooldown

try this

function tower.Attack(newTower, player,amount)
    local multiplier = amount or 1
	local config = newTower.Config
	local target = tower.FindTarget(newTower, config.Range.Value, config.TargetMode.Value)
	
	if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then
       for i = 1,multiplier do
		local targetCFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
				
		newTower.HumanoidRootPart.BodyGyro.CFrame = targetCFrame
		
		animateTowerEvent:FireAllClients(newTower, "Attack", target)
		
		wait(config.AnimationDelay.Value)

		target.Humanoid:TakeDamage(config.Damage.Value)
		end
	end
    task.wait(config.Cooldown.Value)
	if newTower and newTower.Parent then
		tower.Attack(newTower, player)
	end
end

and make sure to send multiplier at end like this
tower.Attack(“Cowboy”,game.Players.madonchik123,5)

1 Like

just update the code sorry i forgot to put cooldown

check the script that i send it should work fine

1 Like

the script work fine but after the mob died its give me “Humanoid is not a valid model”

try this

function tower.Attack(newTower, player,amount)
    local multiplier = amount or 1
	local config = newTower.Config
	local target = tower.FindTarget(newTower, config.Range.Value, config.TargetMode.Value)
	
	if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then
       for i = 1,multiplier do
		local targetCFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
				
		newTower.HumanoidRootPart.BodyGyro.CFrame = targetCFrame
		
		animateTowerEvent:FireAllClients(newTower, "Attack", target)
		
		wait(config.AnimationDelay.Value)
           if target:FindFirstChild("Humanoid") then
		       target.Humanoid:TakeDamage(config.Damage.Value)
           end
		end
	end
    task.wait(config.Cooldown.Value)
	if newTower and newTower.Parent then
		tower.Attack(newTower, player)
	end
end

now its humanoidRootpart not a valid member of model lol