--// Connections

IB:connect(function(input, chat)
	if not chat then
		if input.KeyCode == Settings.FireCannonKey then
			if not CannonReload then
				CannonReload = true

				Storage.FireCannon:FireServer(System.Gun.Missile, SettingsS, ExplosiveMissileScript, SmokeMissileScript, HeatMissileScript, System, ShellType)
				
				wait(Settings.CannonReload)
				
				CannonReload = false
			end
		elseif input.KeyCode == Settings.RotateSystemLeftKey then
			if not RotRightKeyDown then
				RotLeftKeyDown = true
				
				Storage.Sound:FireServer(Seat.Swiv, true)
				while true do
					if RotLeftKeyDown then
						wait(Settings.SystemTurnRate)
						Degrees = Degrees + 1
						Storage.RotateSystem:FireServer(Servo, Degrees)
					else
						Storage.Sound:FireServer(Seat.Swiv, false)
						break
					end
				end
			end
		elseif input.KeyCode == Settings.RotateSystemRightKey then
			if not RotLeftKeyDown then
				RotRightKeyDown = true
				Storage.Sound:FireServer(Seat.Swiv, true)
				
				while true do
					if RotRightKeyDown then
						wait(Settings.SystemTurnRate)
						Degrees = Degrees - 1
				
						Storage.RotateSystem:FireServer(Servo, Degrees)
					else
						Storage.Sound:FireServer(Seat.Swiv, false)
					
						break
					end
				end
			end
		elseif input.KeyCode == Settings.IncreaseAltKey then
			if not DecreaseAltKeyDown then
				IncreaseAltKeyDown = true
				Storage.Sound:FireServer(Seat.VertSound, true)
			
				while true do
					if IncreaseAltKeyDown then
						if Degrees2 >= MaxUp then
							IncreaseAltKeyDown = false
							Storage.Sound:FireServer(Seat.VertSound, false)
							
							break
						else
							wait(Settings.GunMoveRate)
					
							Degrees2 = Degrees2 + 1
					
							Storage.RotateGun:FireServer(Servo2, Degrees2)
						end
					else
						Storage.Sound:FireServer(Seat.VertSound, false)
						
						break
					end
				end
			end
		elseif input.KeyCode == Settings.DecreaseAltKey then
			if not IncreaseAltKeyDown then
				DecreaseAltKeyDown = true
				Storage.Sound:FireServer(Seat.VertSound, true)
				
				while true do
					if DecreaseAltKeyDown then
						if Degrees2 <= MaxDown then
							DecreaseAltKeyDown = false
						
							Storage.Sound:FireServer(Seat.VertSound, false)
							break
						else
							wait(Settings.GunMoveRate)
					
							Degrees2 = Degrees2 - 1
							
							Storage.RotateGun:FireServer(Servo2, Degrees2)	
						end
					else
						Storage.Sound:FireServer(Seat.VertSound, false)
						
						break
					end
				end
			end
		elseif input.KeyCode == Settings.AimKey then
			if not Aiming then
				Aiming = true
				AttackMode(true)
			else
				Aiming = false
				AttackMode(false)
			end
		elseif input.KeyCode == Settings.SmokeKey then
			Current.Text = "SELECTED: Smoke"
			ShellType = "Smoke"
		elseif input.KeyCode == Settings.ExplosKey then
			Current.Text = "SELECTED: Explosive"
			ShellType = "Explosive"
		elseif input.KeyCode == Settings.HeatKey then
			Current.Text = "SELECTED: HEAT"
			ShellType = "Heat"
		end
	end
end)

IE:connect(function(input, chat)
	if not chat then
		if input.KeyCode == Settings.RotateSystemRightKey then
			RotRightKeyDown = false
		elseif input.KeyCode == Settings.RotateSystemLeftKey then
			RotLeftKeyDown = false
		elseif input.KeyCode == Settings.DecreaseAltKey then
			DecreaseAltKeyDown = false
		elseif input.KeyCode == Settings.IncreaseAltKey then
			IncreaseAltKeyDown = false
		end
	end
end)

SmokeB.MouseButton1Down:connect(function()
	Current.Text = "SELECTED: Smoke"
	ShellType = "Smoke"
end)

ExploB.MouseButton1Down:connect(function()
	Current.Text = "SELECTED: Explosive"
	ShellType = "Explosive"
end)

HeatB.MouseButton1Down:connect(function()
	Current.Text = "SELECTED: HEAT"
	ShellType = "Heat"
end)

JR:connect(function()
	UIS.MouseIconEnabled = true
	MainGUI:Destroy()
	script:Destroy()
end)

RST:connect(function()
	if Aiming then
		cam.CFrame = System.Gun.AimPart.CFrame
	end
end)
