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)