I was wondering if you could help me make an ammo system for my game. Thank you :)

My script:


repeat
	wait()
until game:IsLoaded()
	
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://6455978762"
local track

local tool = script.Parent
local handle = tool:WaitForChild("Handle")

local plr = game.Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
local maxAmmo = 8

local shoot = false
local equip = false

local projectiles = 8
 --number of bullets shot at once
local spread = 4 --bullet spread
local damage = 13 --hit damage
local cooldown = 1.2 --shoot delay

mouse.TargetFilter = char --doesn't scan character

function newbullet()
	local x = math.random(-spread*100,spread*100)/100
	local y = math.random(-spread*100,spread*100)/100

	local direction = (CFrame.new(handle.CFrame.p,mouse.Hit.p)*CFrame.Angles(math.rad(x),math.rad(y),0)).lookVector
	local ray = Ray.new(handle.CFrame.p,(direction).unit*999)
	local part,pos = workspace:FindPartOnRay(ray,char)

	if part then
		if part.Parent.Name ~= plr.Name then
			tool:WaitForChild("ShootEvent"):FireServer(part,pos,damage)
		end
	end
end

mouse.Button1Down:Connect(function()
	if equip then
		if shoot == false then
			shoot = true

			for i = 1,projectiles do
				newbullet()
			end
			
			wait(cooldown)

			shoot = false
		end
	end
end)

tool.Equipped:Connect(function()
	equip = true
	track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
	track.Priority = Enum.AnimationPriority.Movement

	track:Play()
end)

tool.Unequipped:Connect(function()
	equip = false
	track:Stop()
end)