After unequipping tool, script.Parent.Activated:Connect executes twice?
WARNING: VERY CRAPPY CODE!
Whenever I unequip my gun (not dropping) and re-equip, it works normally except for
script.Parent.Activated:Connect(function()
@ (Line 81)
The line executes multiple times for a reason I cant explain. Here is my local script:
003 | local ShootDelay = 0.2 |
005 | local ReloadTime = 7.5 |
007 | local Unequipped = false |
009 | local Reloading = false |
010 | local MuzzleOn = false |
011 | local player = game.Players.LocalPlayer |
012 | local char = player.Character or player.CharacterAdded:wait() |
013 | local humanoid = char:WaitForChild( "Humanoid" ) |
014 | local Mouse = game.Players.LocalPlayer:GetMouse() |
015 | local camera = workspace.CurrentCamera |
020 | local AnimationStatus = "Off" |
021 | local animationOn = script.Parent:WaitForChild( 'On' ) |
022 | local On = humanoid:LoadAnimation(animationOn) |
027 | local function nowits 6 rlly() |
028 | if AnimationStatus = = "On" then |
031 | elseif AnimationStatus = = "Off" then |
037 | local function CreateMotor 6 D() |
038 | local PlayerGunConnect = Instance.new( "Motor6D" ) |
039 | PlayerGunConnect.Part 0 = player.Character:WaitForChild( "Right Arm" ) |
040 | PlayerGunConnect.Part 1 = script.Parent.MainAssembly |
041 | PlayerGunConnect.C 0 = CFrame.new( 0 ,- 3.5 ,- 0.63 ) |
042 | PlayerGunConnect.C 1 = CFrame.Angles(math.rad( 90 ), 0 , math.rad( 180 )) |
043 | PlayerGunConnect.Parent = script.Parent.Motor 6 D |
046 | local function DestroyMotor 6 D() |
047 | local test = script.Parent.Motor 6 D:FindFirstChild( "Motor6D" ) |
049 | script.Parent.Motor 6 D.Motor 6 D:Destroy() |
053 | local function CamShake() |
056 | char.Humanoid.CameraOffset = Vector 3. new(math.random(-MaxCamShake,MaxCamShake), math.random(-MaxCamShake,MaxCamShake), math.random(-MaxCamShake,MaxCamShake)) |
058 | char.Humanoid.CameraOffset = Vector 3. new( 0 , 0 , 0 ) |
061 | script.Parent.Equipped:Connect( function () |
063 | AnimationStatus = "On" |
066 | script.Parent.MuzzleFlash:FireServer(MuzzleOn) |
068 | local function Reload() |
071 | script.Parent.RELOAD:FireServer() |
072 | local animationReload = script.Parent:WaitForChild( 'Reload' ) |
073 | local Reload = humanoid:LoadAnimation(animationReload) |
074 | Reload.Looped = false |
081 | script.Parent.Activated:Connect( function () |
082 | if Ammo> 0 and not Reloading and counter = = 0 or counter = = 1 then |
084 | script.Parent.RayCastEvent:FireServer(script.Parent.BulHol.CFrame.Position, Mouse.Hit.Position) |
085 | local animationShoot = script.Parent:WaitForChild( 'Shoot' ) |
086 | local Shoot = humanoid:LoadAnimation(animationShoot) |
089 | script.Parent.MuzzleFlash:FireServer(MuzzleOn) |
092 | script.Parent.MuzzleFlash:FireServer(MuzzleOn) |
093 | if Unequipped = = true then |
096 | elseif not Reloading and Ammo = = 0 and counter = = 0 then |
099 | elseif counter = = 1 then |
103 | print (counter .. "yes" ) |
107 | script.Parent.Unequipped:Connect( function () |
108 | print ( "unequipped, ammo is at " .. Ammo .. " bullet(s)" ) |
111 | AnimationStatus = "Off" |