Gun firing when not equipped

So I have this issue where I will switch guns and when I shoot, it will shoot both the gun I have equipped and the gun I had equipped. Switching to the original gun and reloading fixes this, but I was wondering if anyone else had this issue and knew of an easy fix. It will even do it when I have a sword equipped.

I could post the scripts and everything, but it is a lot of code to go through. It is the free model FE Gun Kit found here:

https://www.roblox.com/library/1351145410/FE-Gun-Kit-Edited-Version-UPDATE

Thanks.

can you give us the script? It’s probably because you didn’t use :Disconnect()

After reading up on :Disconnect(), it seems like I should create a variable and set the connection to the variable and then disconnect the variable on unequipping. Does that sound right? Here is the code from the local script that I think should be used:

Mouse.Button1Down:connect(function()
	if not UserInputService.TouchEnabled then
	Down = true
	local IsChargedShot = false
	if Equipped and Enabled and Down and not Reloading and not HoldDown and Mag > 0 and Humanoid.Health > 0 then
		Enabled = false
		if Module.ChargedShotEnabled then
			if HandleToFire:FindFirstChild("ChargeSound") then HandleToFire.ChargeSound:Play() end
			wait(Module.ChargingTime)
			IsChargedShot = true
		end
		if Module.MinigunEnabled then
			if HandleToFire:FindFirstChild("WindUp") then HandleToFire.WindUp:Play() end
			wait(Module.DelayBeforeFiring)
		end
		while Equipped and not Reloading and not HoldDown and (Down or IsChargedShot) and Mag > 0 and Humanoid.Health > 0 do
			IsChargedShot = false
			
			Player.PlayerScripts.BulletVisualizerScript.VisualizeM:Fire(nil,HandleToFire,
				                                                       Module.MuzzleFlashEnabled,
			                                                          {Module.MuzzleLightEnabled,Module.LightBrightness,Module.LightColor,Module.LightRange,Module.LightShadows,Module.VisibleTime},
			                                                           script:WaitForChild("MuzzleEffect"))
			VisualizeMuzzle:FireServer(HandleToFire,
				            Module.MuzzleFlashEnabled,
						    {Module.MuzzleLightEnabled,Module.LightBrightness,Module.LightColor,Module.LightRange,Module.LightShadows,Module.VisibleTime},
						    script:WaitForChild("MuzzleEffect"))	
			
			for i = 1,(Module.BurstFireEnabled and Module.BulletPerBurst or 1) do
				--VVV Edit here VVV--
				self.knockback.t = 1 * Vector3.new(-1, -20 * .005, 0)
				--^^^ Edit here ^^^--
				spawn(RecoilCamera)
				EjectShell(HandleToFire)
				CrosshairModule.crossspring:accelerate(Module.CrossExpansion)		
				for x = 1,(Module.ShotgunEnabled and Module.BulletPerShot or 1) do
					Fire(HandleToFire, Mouse)
				end
				Mag = Mag - 1
				ChangeMagAndAmmo:FireServer(Mag,Ammo)
				UpdateGUI()
				if Module.BurstFireEnabled then wait(Module.BurstRate) end
				if Mag <= 0 then break end
			end
			HandleToFire = (HandleToFire == Handle and Module.DualEnabled) and Handle2 or Handle
			wait(Module.FireRate)
			if not Module.Auto then break end
		end
		if HandleToFire.FireSound.Playing and HandleToFire.FireSound.Looped then HandleToFire.FireSound:Stop() end
		if Module.MinigunEnabled then
			if HandleToFire:FindFirstChild("WindDown") then HandleToFire.WindDown:Play() end
			wait(Module.DelayAfterFiring)
		end
		Enabled = true
		if Mag <= 0 then Reload() end
	end
	end
end)
Mouse.Button1Up:connect(function()
	if not UserInputService.TouchEnabled then
	    Down = false
	end
end)

ChangeMagAndAmmo.OnClientEvent:connect(function(ChangedMag,ChangedAmmo)
	Mag = ChangedMag
	Ammo = ChangedAmmo
	UpdateGUI()
end)
Tool.Equipped:connect(function(TempMouse)
	GUI.Parent = Player.PlayerGui
	UpdateGUI()
	Handle.EquippedSound:Play()
	if Module.WalkSpeedRedutionEnabled then
	Humanoid.WalkSpeed = Humanoid.WalkSpeed - Module.WalkSpeedRedution
	else
	Humanoid.WalkSpeed = Humanoid.WalkSpeed
	end
	CrosshairModule:setcrosssettings(Module.CrossSize, Module.CrossSpeed, Module.CrossDamper)
	UserInputService.MouseIconEnabled = false
	if EquippedAnim then EquippedAnim:Play(nil,nil,Module.EquippedAnimationSpeed) end
	if IdleAnim then IdleAnim:Play(nil,nil,Module.IdleAnimationSpeed) end
	delay(Module.EquippingTime, function()
	    Equipped = true
	    if Module.AmmoPerMag ~= math.huge then GUI.Frame.Visible = true end
	end)
	TempMouse.KeyDown:connect(function(Key)
		if string.lower(Key) == "r" then
			Reload()
		elseif string.lower(Key) == "e" then
			if not Reloading and not HoldDown and Module.HoldDownEnabled then
				HoldDown = true
				IdleAnim:Stop()
                if HoldDownAnim then HoldDownAnim:Play(nil,nil,Module.HoldDownAnimationSpeed) end
    		    if AimDown then 
                    TweeningService:Create(Camera, TweenInfo.new(Module.TweenLengthNAD, Module.EasingStyleNAD, Module.EasingDirectionNAD), {FieldOfView = 70}):Play()
			        CrosshairModule:setcrossscale(1)
			        --[[local GUI = game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("ZoomGui")
			        if GUI then GUI:Destroy() end]]
		        	Scoping = false
			        game:GetService("Players").LocalPlayer.CameraMode = Enum.CameraMode.Classic
			        UserInputService.MouseDeltaSensitivity = InitialSensitivity
			        AimDown = false
	        	end
			else
				HoldDown = false
				IdleAnim:Play(nil,nil,Module.IdleAnimationSpeed)
                if HoldDownAnim then HoldDownAnim:Stop() end
			end
		end
	end)
	Mouse.Button2Down:connect(function()
		if not Reloading and not HoldDown and AimDown == false and Equipped == true and Module.IronsightEnabled and (Character.Head.Position - Camera.CoordinateFrame.p).magnitude <= 1 then
			    TweeningService:Create(Camera, TweenInfo.new(Module.TweenLength, Module.EasingStyle, Module.EasingDirection), {FieldOfView = Module.FieldOfViewIS}):Play()
                CrosshairModule:setcrossscale(Module.CrossScaleIS)
				--[[local GUI = game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("ZoomGui") or Tool.ZoomGui:Clone()
				GUI.Parent = game:GetService("Players").LocalPlayer.PlayerGui]]
				--Scoping = false
				game:GetService("Players").LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
				UserInputService.MouseDeltaSensitivity = InitialSensitivity * Module.MouseSensitiveIS
				AimDown = true
		elseif not Reloading and not HoldDown and AimDown == false and Equipped == true and Module.SniperEnabled and (Character.Head.Position - Camera.CoordinateFrame.p).magnitude <= 1 then
			    TweeningService:Create(Camera, TweenInfo.new(Module.TweenLength, Module.EasingStyle, Module.EasingDirection), {FieldOfView = Module.FieldOfViewS}):Play()
				CrosshairModule:setcrossscale(Module.CrossScaleS)
				--[[local GUI = game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("ZoomGui") or Tool.ZoomGui:Clone()
				GUI.Parent = game:GetService("Players").LocalPlayer.PlayerGui]]
			    local zoomsound = GUI.Scope.ZoomSound:Clone()
	            zoomsound.Parent = Player.PlayerGui
	            zoomsound:Play()
				Scoping = true
				game:GetService("Players").LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
				UserInputService.MouseDeltaSensitivity = InitialSensitivity * Module.MouseSensitiveS
				AimDown = true
				game:GetService("Debris"):addItem(zoomsound,zoomsound.TimeLength)
			end
	end)
	Mouse.Button2Up:connect(function()
		if AimDown then
            TweeningService:Create(Camera, TweenInfo.new(Module.TweenLengthNAD, Module.EasingStyleNAD, Module.EasingDirectionNAD), {FieldOfView = 70}):Play()
			CrosshairModule:setcrossscale(1)
			--[[local GUI = game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("ZoomGui")
			if GUI then GUI:Destroy() end]]
			Scoping = false
			game:GetService("Players").LocalPlayer.CameraMode = Enum.CameraMode.Classic
			UserInputService.MouseDeltaSensitivity = InitialSensitivity
			AimDown = false
		end
	end)
	if Module.DualEnabled and not workspace.FilteringEnabled then
		Handle2.CanCollide = false
		local LeftArm = Tool.Parent:FindFirstChild("Left Arm") or Tool.Parent:FindFirstChild("LeftHand")
		local RightArm = Tool.Parent:FindFirstChild("Right Arm") or Tool.Parent:FindFirstChild("RightHand")
		if RightArm then
			local Grip = RightArm:WaitForChild("RightGrip",0.01)
			if Grip then
				Grip2 = Grip:Clone()
				Grip2.Name = "LeftGrip"
				Grip2.Part0 = LeftArm
				Grip2.Part1 = Handle2
				--Grip2.C1 = Grip2.C1:inverse()
				Grip2.Parent = LeftArm
			end
		end
	end
end)
Tool.Unequipped:connect(function()
	HoldDown = false
	Equipped = false
	GUI.Parent = script
	GUI.Frame.Visible = false
	if Module.WalkSpeedRedutionEnabled then
	Humanoid.WalkSpeed = Humanoid.WalkSpeed + Module.WalkSpeedRedution
	else
	Humanoid.WalkSpeed = Humanoid.WalkSpeed
	end
	UserInputService.MouseIconEnabled = true
	if IdleAnim then IdleAnim:Stop() end
	if HoldDownAnim then HoldDownAnim:Stop() end
		if AimDown then
            TweeningService:Create(Camera, TweenInfo.new(Module.TweenLengthNAD, Module.EasingStyleNAD, Module.EasingDirectionNAD), {FieldOfView = 70}):Play()
			CrosshairModule:setcrossscale(1)
			--[[local GUI = game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("ZoomGui")
			if GUI then GUI:Destroy() end]]
			Scoping = false
			game:GetService("Players").LocalPlayer.CameraMode = Enum.CameraMode.Classic
			UserInputService.MouseDeltaSensitivity = InitialSensitivity
			AimDown = false
		end
	if Module.DualEnabled and not workspace.FilteringEnabled then
		Handle2.CanCollide = true
		if Grip2 then Grip2:Destroy() end
	end
end)
1 Like

I see the problem, you need to use :Disconnect():

Equip = Tool.Equipped:Connect(function() end)
    mouseEvent = Mouse.Button1Down:connect(function() end)
end)
Tool.Unequipped:connect(function()
    Equip:Disconnect()
    mouseEvent:Disconnect()
end)

thanks, is it important to use globals or can i use a local variable?

That seems to work but when I try to reequip the weapon now it doesn’t shoot.
How do I get it to reconnect on equip?

I tried using just the mouse event but that didn’t work either.

It doesn’t really matter(I think)

maybe change it to this:

local Equip 
Tool.Equipped:Connect(function()
    mouseEvent = Mouse.Button1Down:connect(function() end)
end)

Tell me if there are any errors(Can you show the script you are using as of now?)

Actually I found an error message in the bullet visualizer script where it wasn’t locating the HumanoidRootPart after the gun was unequipped while trying to calculate body velocity in bullet trajectory. I just took this part out and it doesn’t error or cause the bug. I thought I already posted that, but I was mistaken. Sorry to take up your time, but thanks.