Need to implement a system where u can only shoot 5balls at a time in one click

I have a script where u shoot balls at noobs to get coins but right now as log as the noobs are in the maxrabge then they can get shot no matter how many ur shooting I there to be a max balls u can shoot at once here is my script

local plr = game.Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
local tweenService = game:GetService("TweenService")
local debounce = false

mouse.Button1Down:Connect(function()
	local hrp = char.HumanoidRootPart

	if debounce == false then
		debounce = true
		for i, v in pairs(game.Workspace.Noobs:GetChildren()) do
			if v:FindFirstChild("Humanoid") then
				if v.Name == plr.Name then
					return 
				else
					local hrp = v:FindFirstChild("HumanoidRootPart")
					local sphere = plr.PlayerScripts.Sphere1:Clone() or plr.PlayerScripts.Sphere2:Clone()
					local maxrange = 10
					if plr.PlayerScripts:FindFirstChild("Sphere2") then
						sphere = plr.PlayerScripts.Sphere2:Clone()
						maxrange = 15
					end
					if plr.PlayerScripts:FindFirstChild("Sphere3")then
						sphere = plr.PlayerScripts.Sphere3:Clone()
						maxrange = 25
					end
					sphere.Parent = game.Workspace.OutCastSpheres
					local distance = (hrp.Position - char:FindFirstChild("HumanoidRootPart").Position).Magnitude
					if distance <= maxrange then


						local tweenInfo = TweenInfo.new(
							0.6, --seconds to complete
							Enum.EasingStyle.Quint, --easing style
							Enum.EasingDirection.Out, --easing direction
							0, --repeat count
							false, --reverses?
							0 --delay before starting
						)

						local properties = {
							Position = v:FindFirstChild("HumanoidRootPart").Position
						}

						wait()
						game.SoundService.Laser:Play()
						sphere.Position = char:FindFirstChild("HumanoidRootPart").Position
						local tween = tweenService:Create(sphere, tweenInfo, properties)

						tween:Play()

						game.ReplicatedStorage.SphereShooter:FireServer(v,plr,sphere.Dmg.Value)
						game.Debris:AddItem(sphere,0.6)


						local tw = TweenInfo.new(
							0.6, --seconds to complete
							Enum.EasingStyle.Quint, --easing style
							Enum.EasingDirection.Out, --easing direction
							0, --repeat count
							false, --reverses?
							0 --delay before starting
						)

						local hitbox = game.ReplicatedStorage.HitBoxPart:Clone()
						hitbox.Parent = workspace
						hitbox.Position = v:FindFirstChild("HumanoidRootPart").Position
						hitbox.Size = Vector3.new(1,1,1)

						local props = {
							Size = Vector3.new(10,10,10)
						}
						local tween2 = tweenService:Create(hitbox, tw, props)

						tween2:Play()
						game.Debris:AddItem(hitbox,0.6)

					else
						sphere:Destroy()
					end
				end
			end
		end
	else return end
	wait(0.5)
	debounce = false
end)

how would I add a system where they can only shoot 5 balls at a time?? im not sure how to implement that or how to do it at all

Add an ammo system.

local ammo = 5

Then, when shooting:

if ammo >= 5 then
    ammo -= 1
    --shooting code goes here


    --put the following lines at the bottom of the subprogram
    task.wait(1)
    ammo += 1
end

oooh I haven’t thought of that thanks ill try this

This won’t work cuz it’ll only do make an ammo system I want it where the max balls u can shoot in one click is 5 in one click the 5 balls can go to 5 noobs instead of how many are in the max range

What do you mean “in one click”? Do you mean like they can put their mouse button down and hold?
These might be helpful:

--set length iteration (for loop)
for i = 5, 0, -1 do
end

--IsMouseButtonPressed
local uis = game:GetService("UserInputService")
uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) --returns a Boolean

--MouseEvents
local mouse = game:GetService("Players").LocalPlayer:GetMouse()

mouse.Button1Down:Connect(aSubprogramGoesHere)

I mean like they click once it shoots 5 balls to the 5 dummies in the 50 stud range but if there are 7 dummies in the 50 studs it’ll shoot all 7 I just want it to shoot 5 in the maxrange even if there are 7 in the max range ya know?

An iteration is probably the way to go with this. You could even have an array of the dummies in the radius to shoot at.

local dummies = {}

for i = 0, 5, 1 do
    local dummy = dummies[i]
    --shoot a ball at the dummy
end

--maybe bind a function to RunService's RenderStep to update the array of dummies.