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)