Automatic gun shoots faster when left click is spammed

hi

i was spam clicking the gun and i realized it shoots faster.

my code is here:

Mouse.Button1Down:Connect(function()
	if CurrentBooleans.Equipped and not CurrentBooleans.AimCooldown and CurrentBooleans.CanShoot and not CurrentBooleans.AutoShooting and not SettingModule.Burst and SettingModule.Auto and CurrentBooleans.ActuallyEquipped and CurrentBooleans.Aiming and not CurrentBooleans.Reloading and Tool:GetAttribute("Ammo") > 0 then
		CurrentBooleans.AutoShooting = true
		while CurrentBooleans.AutoShooting and task.wait(SettingModule.FireRate) do
			Mouse.Button1Up:Connect(function()
				CurrentBooleans.AutoShooting = false
			end)
			Network:FireServer("Fire"..NetworkKeys:FindFirstChild(Player.Name).ID.Value)
			if SettingModule.GunFiringBlurEnabled then
				Thread:Spawn(function()
					local Blur = game.Lighting:FindFirstChild("GunBlur")
					if Blur then
						Blur.Enabled = true
						Thread:Wait(0.28)
						Blur.Enabled = false
					end
				end)
			end
			Thread:Spawn(RecoilCamera)
			Fire(Mouse.Hit.p)
			CurrentAnimTable.FireAnimation:Play()
			Tool.Server.ChangeAmmoAndMag:FireServer(Tool:GetAttribute("Ammo") - 1, Tool:GetAttribute("Mag"))
			CreateShell()
		end
	end

the video is here.

https://streamable.com/e8meb6

You could add a debounce, I’m assuming you know how to do that, else you may ask me.

You mean booleans? I guess I know how to do that but It didn’t fixed my problem.

So you’ve tried something like this?

local Debounce = false
local DebounceDelay = 1

while true do
	if not Debounce then
		Debounce = true
		
		-- Code
		
		task.wait(DebounceDelay)
		Debounce = false
	end
end

Still didn’t fixed my problem. It crashed my studio.

image

What was your DebounceDelay? I tested that code snippet myself and it ran fine, so you obviously changed something.

Mouse.Button1Down:Connect(function()
	if CurrentBooleans.Equipped and not CurrentBooleans.AimCooldown and CurrentBooleans.CanShoot and not CurrentBooleans.AutoShooting and not SettingModule.Burst and SettingModule.Auto and CurrentBooleans.ActuallyEquipped and CurrentBooleans.Aiming and not CurrentBooleans.Reloading and Tool:GetAttribute("Ammo") > 0 then
		CurrentBooleans.AutoShooting = true
		while true do
			if not CurrentBooleans.AutoShooting then
				CurrentBooleans.AutoShooting = true
				Network:FireServer("Fire"..NetworkKeys:FindFirstChild(Player.Name).ID.Value)
				if SettingModule.GunFiringBlurEnabled then
					Thread:Spawn(function()
						local Blur = game.Lighting:FindFirstChild("GunBlur")
						if Blur then
							Blur.Enabled = true
							Thread:Wait(0.28)
							Blur.Enabled = false
						end
					end)
				end
				Thread:Spawn(RecoilCamera)
				Fire(Mouse.Hit.p)
				CurrentAnimTable.FireAnimation:Play()
				Tool.Server.ChangeAmmoAndMag:FireServer(Tool:GetAttribute("Ammo") - 1, Tool:GetAttribute("Mag"))
				CreateShell()
				task.wait(SettingModule.FireRate)
				CurrentBooleans.AutoShooting = false
			end
		end
	end

It’s 0.2. I tried it. Guess it’s not working

Sorry for not explaining it in every minute detail, but you’re supposed to have the debounce affect the Mouse.Button1Down event and not the while loop. Also not including your tables such as CurrentBooleans and Thread can make your code unreadable sometimes.

Thank you. That really worked.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.