Automatic Gun Issues

I made an automatic gun and everything works fine when you hold down your mouse, but when you spam click it it just fires really fast when its supposed to wait for a set cooldown. I tried adding in denounce but it still wont work, here’s my code let me know if you need a better explanation.

local tool = script.Parent
local shootDb = true
local shooting = false
local fireRate = .15

tool.Equipped:Connect(function(mouse)	
	tool.Activated:Connect(function()
		if shootDb == true then
			shootDb = false
			shooting = true
			
			while shooting do
				if ammo > 0 and shootDb == false then
					-- gun stuff
				end	
				wait(fireRate)
			end
		end	
	end)
	
	tool.Deactivated:Connect(function()
		shooting = false
		wait(fireRate)
		shootDb = true
	end)	
end)

Maybe increase the firerate number to something like 0.5 and have a separate number for when holding the trigger.

I tried this it didn’t work, what do you mean?

Increase the firerate number to 1, and see if it still fires very fast.

Yes if i spam it enough it will still fire.