Why is my gun shooting so slowly?

I decided to make my gun automatic but the thing is it shoots like 1 bullet per second. any way to speed it up? I cant find any waits that could be slowing it down.

Local script

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()

shooting = false

script.Parent.Parent.Activated:Connect(function()
	mouse.Button1Down:Connect(function()
		
		shooting = true
		while shooting do
			wait()
			if script.Parent.Parent.AmmoCounter.Value  >=1 then

				local raycastParams = RaycastParams.new()
				raycastParams.FilterDescendantsInstances = {player.Character}
				raycastParams.FilterType = Enum.RaycastFilterType.Blacklist

				local rayOrigin = script.Parent.Position

				local raycastResult = workspace:Raycast(rayOrigin, mouse.UnitRay.Direction* 250 , raycastParams)



				script.Parent.Parent.FireGun:FireServer(mouse.Hit.Position)


				local RunService = game:GetService("RunService")

				local Camera = workspace.CurrentCamera

				local RecoilTime = 0.1
				local RecoilHeight = 1.1
				local NegativeRecoilTime = 0.05

				local DistanceShake = 0
				local SpeedShake = 0

				local IncrementTime = 0.25   --0 to 1

				local Connection, TwoConnection

				local function PlayRecoil()

					local TotalSpeed = SpeedShake * tick()
					local bobbleX = math.cos(TotalSpeed * DistanceShake)
					local bobbleY = math.abs(math.sin(TotalSpeed)) * DistanceShake


					Camera.CFrame = Camera.CFrame:Lerp(Camera.CFrame * CFrame.new(0,bobbleY,0) * CFrame.Angles(math.rad(RecoilHeight),0,0), IncrementTime)

				end


				local function RecoverRecoil()
					Camera.CFrame = Camera.CFrame:Lerp(Camera.CFrame * CFrame.Angles(math.rad(-NegativeRecoilTime),0,0), IncrementTime) 
				end



				Connection = RunService.RenderStepped:Connect(PlayRecoil)
				wait(RecoilTime)
				Connection:Disconnect()
				wait()
				TwoConnection = RunService.RenderStepped:Connect(RecoverRecoil)
				wait(RecoilTime)
				TwoConnection:Disconnect()
			else
				print("NO AMMO")
			end
			
			mouse.Button1Up:Connect(function()
				shooting = false
			end)
			
			
		end
		
	end)

end)

Fire gun event script


local deBounce = true

script.Parent.Parent.FireGun.OnServerEvent:Connect(function(player,mouse)

	
	local gui = player.PlayerGui.ScorpionGui

	local ammo = script.Parent.Parent.AmmoCounter
	
	
	if ammo.Value <1 then
		print("OUT OF AMMO")
	else
		if deBounce == true then
			deBounce = false

			local MousePosition = mouse --Your mouse position from remote event
			local origin = script.Parent.Position-- your origin

			local Direction = (MousePosition - origin).Unit
			local raycastParams = RaycastParams.new()
			raycastParams.FilterDescendantsInstances = {script.Parent.Parent, player.Character}
			raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
			local ray = workspace:Raycast(origin,Direction * 3500, raycastParams)



			ammo.Value = ammo.Value - 1

			gui.TextLabel.LocalScript.Shot:FireClient(player)


			script.Parent.Parent.Handle.FireSound:Play()
			
			
			

			if ray then
				


				

				local target = ray.Instance:FindFirstAncestorOfClass("Model")
				local BTarget = ray.Instance
				
				
				local hole = game.ReplicatedStorage.BulletHole:Clone()
				hole.Parent = BTarget 
				hole.CFrame = CFrame.new(ray.Position, ray.Position + ray.Normal)
				
				
				local WeldConstraint = Instance.new("WeldConstraint", hole)
				WeldConstraint.Part0 = hole
				WeldConstraint.Part1 = ray.Instance
				
				game.Debris:AddItem(hole, 33)

				if target then
					local hittarget =	target:FindFirstChildOfClass("Humanoid")
					if hittarget then
						hittarget.Health = hittarget.Health - 10
					end
				end

			end

			wait()
			deBounce = true
		end
	end


end)

Why not just do PlayRecoil()?

Why not just do RecoverRecoil()?

3 Likes

This wasnt the fix but its right where the fix is thanks