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